Cookbook

How to add watermarks and background images

Word allows to add watermarks and backgrounds to a page. Each of them has its own strenghts and weaknesses. The main difference between these two formats is that a background doesn't appear in PDFs nor in print copies, while the watermark does.

phpdocx supports them both.

Add a background image in documents

The addBackgroundImage method lets you place a background image that covers the whole page. If the image doesn't cover it entirely, the method repeats it as many times as necessary to fill the page.

To insert a background image, run the following code:

Insert a watermark to a DOCX (Advanced and Premium licenses only)

The DocxUtilities class includes the watermarkDocx method, that places a watermark with an image format to a page. The image that works as a watermark keeps its original size and doesn't repeat itself along the page like the images added using the addBackgroundImage method.

You can place a watermark with this code:

Beside images, the watermarkDocx method also allows to add texts as watermarks.

Insert a watermark to a PDF (Advanced and Premium licenses only)

The DocxUtilities class includes the watermarkPdf method, to insert a watermark image or text in PDF documents.

You can place a watermark with this code:

Beside images, the watermarkPdf method also allows to add texts as watermarks.