PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Error in the image size when generating PDF from Spreadsheet

Open brnyza opened this issue 4 years ago • 3 comments

- [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. error_Dompdf

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.4.10 PhpSpreadsheet 1.15

brnyza avatar Oct 26 '20 19:10 brnyza

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.

stale[bot] avatar Dec 25 '20 21:12 stale[bot]

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"

lyoha avatar Aug 14 '21 18:08 lyoha

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.

oleibman avatar Sep 03 '22 01:09 oleibman

Closing, no update in 4 months, no sample to work with.

oleibman avatar Jan 25 '23 04:01 oleibman