Forum


Replies: 1   Views: 1711
Watermark in pdf not covering hole page
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 dadinos2  · 27-03-2020 - 20:39

I have a A4 PDF and I want to cover the hole background with a image ( like a company letterpaper)

I have this code:

require_once '../App/phpdoc/classes/PdfUtilities.php';
$docx = new PdfUtilities();
 $docx->watermarkPdf($source, $target, 'image', array('image' => 'images/briefpapier.png', 'remove_previous_watermarks' => true, 'opacity'=> 1,  'decolorate'=> false, 'positionX' => 0, 'positionY' => 0));

But i does not cover the hole page. I can shift the position a little bit with positionX an positionY.

No scaling possible. I tried different image resolutions but no go.

I have the latest 9.5 version installed.

The name 'watermark' suggest its loaded in the back of the current PDF content but it's placed above it. So I use a tranparent PNG to reach the goal of a backgound watermark. But it always is covering about 80% of the page and not the hole 100%.

Is there a solution to cover the hole page?

Thanks in advance!

Aren

 

Posted by admin  · 28-03-2020 - 11:11

Hello,

UPDATE: phpdocx 11 added the addBackgroundImage method to PDFUtilities.

The current version of phpdocx doesn't include an option to cover the whole page with a watermark when working with PDF. For example, working with DOCX documents, you can't cover the whole page with an image using watermarkDOCX, you need to use addBackgroundImage
We move the request to the dev team to add support; some margins should be removed/changed to get a whole image background and the image should be added to the header instead of the main content (https://tcpdf.org/examples/example_051/). As it's a task that can't be accomplished using the current version of phpdocx, if you open a support ticket (https://www.phpdocx.com/support) and attach the PDF and the image you are using, the dev team will check them and generate a custom class to accomplish that task.

About the opacity question, your script is using:

'opacity'=> 1

You don't need to use a transparent PNG, the default opacity value is 0.5, but setting it to 1 you remove the applied transparency, you should use a lower value:

'opacity'=> 0.3 //  0.5 is the default one if no value is set

Regards.