PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Error in the image size when generating PDF from Spreadsheet
- [x ] a bug report
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
$objDrawing->setImageResource(imagecreatefrompng($img_G5));
$objDrawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setCoordinates('B2');
$objDrawing->setWidthAndHeight(50, 50);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf($spreadsheet);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename='.$fileName);
header('Cache-Control: max-age=0');
$writer->save('php://output');
The image in PDF is not properly resized.
Which versions of PhpSpreadsheet and PHP are affected?
PHP 7.4.10 PhpSpreadsheet 1.15
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.
The problem is caused by incorrectly specified styles for the "img" tag in the PhpSpreadsheet/Writer/Html::writeImageInCell() method. For example, instead of "max-width: 100%" you should set "max-width: auto"
I am unable to duplicate this problem using samples/images/termsconditions.jpg as the source of the Memory Drawing. If you still have a problem with your file, can you please upload the file you used as $img_G5
in your report so that I can investigate further.
Closing, no update in 4 months, no sample to work with.