Forum


Replies: 2   Views: 1199
Watermarkpdf image sizes
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Lochspring  · 17-03-2022 - 20:25

HI there.  We're testing out v12.5, and working through some snags with PDF conversion.  ONe of the items we noticed was that, when passing in images with height and width specified, we're getting images that are consistently the WRONG size.  For example, I added a simple 600x200 jpg, using the code ffrom the examples provided, like so.  

 

<?php
// add an image watermark to an existing PDF

require_once '../../../Classes/Phpdocx/Create/CreateDocx.php';

$docx = new Phpdocx\Utilities\PdfUtilities();

$source = '../../files/Test.pdf';
$target = 'example_watermarkImage3.pdf';

$docx->watermarkPdf($source, $target, 'image', array('image' => 'test2.jpg'));

This works fine, creating my pdf as expected.  However, when I added a height and width param, like so:

 

<?php
// add an image watermark to an existing PDF

require_once '../../../Classes/Phpdocx/Create/CreateDocx.php';

$docx = new Phpdocx\Utilities\PdfUtilities();

$source = '../../files/Test.pdf';
$target = 'example_watermarkImage3.pdf';

$docx->watermarkPdf($source, $target, 'image', array('image' => 'test2.jpg', 'width' => '300', 'height' => '100'));

My image was actually generated at a LARGER size.  I wanted to verify this behavior, so I tried to generate again, only this time, I used the original proportions for my image, 600x200.

<?php
// add an image watermark to an existing PDF

require_once '../../../Classes/Phpdocx/Create/CreateDocx.php';

$docx = new Phpdocx\Utilities\PdfUtilities();

$source = '../../files/Test.pdf';
$target = 'example_watermarkImage3.pdf';

$docx->watermarkPdf($source, $target, 'image', array('image' => 'test2.jpg', 'width'=>'600', 'height'=>'200'));

The image was massive, nearly double in size, and forced itself onto the next page.

I suspect that there may be a pixel conversion problem here, but the DOCX transform doesn't seem to have the problem, only the PDF one.  Any ideas?