How to Generate PDF with Watermark in PHP using Dompdf

Generate PDF with Watermark in PHP using Dompdf

Dynamic PDF age is valuable when you need to enable the client to download the content or HTML content in a file on the web application. For this situation, the HTML content should be changed over to the PDF record before download. You can Convert HTML to PDF in PHP with Dompdf. Dompdf is the most straightforward approach to make PDF file with dynamic information using PHP. Dompdf library help to Generate a PDF document and add the HTML content to PDF using PHP.

Dompdf gives different configuration option to upgrade the PDF generation functionality. Adding Watermark to PDF is a standout helpful functionality among them. In this article tutorial, we will tell you the best way to change over HTML to PDF and add watermark to PDF with Dompdf using PHP.

A watermark is a picture or text that can show up either front or behind the content of the PDF file. In the model code, we will explain the both methods to add text and picture watermark to PDF report with Dompdf in PHP.

In this Article i will show you all the process step by step:

Step-1:

Download the Zip version of dompdf (stable release) from GitHub. Extract the Dompdf package and upload it in the directory of your application.

Step-2:

Include Dompdf autoloader to load dompdf libraries and helper functions in the PHP script.

First we will add Text Watermark to PDF

Add Image Watermark to PDF

The following code generates image watermark PDF with Dompdf library using PHP. The process is the same as like the text watermark code (above) except the image setup.

  • Define the image path which you want to add a watermark. Please upload image in same directory or folder.
  • Add watermark image to PDF document using image() method of Canvas class.

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request

How to Generate PDF from Mysql Database using PHP

How to convert HTML to PDF file in PHP

How to Convert HTML to PDF in CodeIgniter using Dompdf Library

Related posts