{"id":4003,"date":"2019-05-23T18:30:18","date_gmt":"2019-05-23T18:30:18","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=4003"},"modified":"2022-11-22T11:02:26","modified_gmt":"2022-11-22T11:02:26","slug":"create-pdf-with-watermark-in-php-using-dompdf","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/","title":{"rendered":"Create PDF with Watermark in PHP using Dompdf"},"content":{"rendered":"<p><b>Dynamic PDF<\/b> generation is useful when you want to allow the user to download the text or HTML content in a file on the web application. In this case, the HTML content needs to be converted to a PDF file before downloading. You can easily <a href=\"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/\">convert HTML to PDF in PHP<\/a> with Dompdf. Dompdf is the easiest way to create PDF documents with dynamic data using PHP. Dompdf library helps to create a PDF file and add the HTML content to PDF using PHP.<\/p>\n<p>Dompdf provides various configuration options to enhance the PDF creation functionality and customize the PDF document. Add Watermark to PDF is a very useful feature to protect the copyright of the PDF document. In this tutorial, we will show you how to <b>convert HTML to PDF<\/b> and add <b>watermark to PDF<\/b> with Dompdf using PHP.<\/p>\n<p>A watermark is an image or text that can appear either front or behind the content of the PDF document. In the example code, we will show both methods to add text and image watermark to PDF document with Dompdf in PHP.<\/p>\n<h2>Download and Install Dompdf<\/h2>\n<p><b>1.<\/b> First, <a href=\"https:\/\/github.com\/dompdf\/dompdf\/releases\" target=\"_blank\" rel=\"noopener\">download stable release<\/a> of dompdf library, extract the Dompdf package and place it in the directory of your application.<\/p>\n<p><span class=\"note\">Note that:<\/span> You don&#8217;t need to download the Dompdf library separately, all the required files are included in the source code.<\/p>\n<p><b>2.<\/b> Include autoloader to load dompdf library and helper functions in the PHP script.<\/p>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;autoloader <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'dompdf\/autoload.inc.php'<\/span><span style=\"color: #007700\">;<\/span><\/pre>\n<h2>Add Watermark to PDF (text)<\/h2>\n<p>The following example code generates PDF and <b>add watermark text to PDF<\/b> file with Dompdf library using PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Use the reference of the Dompdf, Options, and FontMetrics namespace.<\/li>\n<li>Set the <code>isPhpEnabled<\/code> option to enable embedded PHP.<\/li>\n<li>Instantiate dompdf class.<\/li>\n<li>Add HTML content.<\/li>\n<li>Render the HTML as PDF.<\/li>\n<li>Instantiate canvas instance using <b>getCanvas()<\/b> method of Dompdf class.<\/li>\n<li>Instantiate font metrics class.<\/li>\n<li>Get the page height and width using <b>get_width()<\/b> and <b>get_height()<\/b> of the Canvas class.<\/li>\n<li>Get the family file using <b>getFont()<\/b> method of FontMetrics class and specify the text font.<\/li>\n<li>Specify the text want to add as a watermark.<\/li>\n<li>Get the height and width of text using <b>getFontHeight()<\/b> and <b>getTextWidth()<\/b> of FontMetrics class.<\/li>\n<li>Specify the horizontal and vertical positions of the text.<\/li>\n<li>Write watermark text to PDF document using the <b>text()<\/b> method of Canvas class.<\/li>\n<li>Output the generated PDF using the <b>stream()<\/b> function of Dompdf class.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Dompdf&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Options&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Options<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Font&nbsp;Metrics&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">FontMetrics<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;options&nbsp;to&nbsp;enable&nbsp;embedded&nbsp;PHP <br \/><\/span><span style=\"color: #0000BB\">$options&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Options<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$options<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">set<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'isPhpEnabled'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'true'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;dompdf&nbsp;class <br \/><\/span><span style=\"color: #0000BB\">$dompdf&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$options<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Load&nbsp;HTML&nbsp;content <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">loadHtml<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'&lt;h1&gt;Welcome&nbsp;to&nbsp;CodexWorld.com&lt;\/h1&gt;'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;(Optional)&nbsp;Setup&nbsp;the&nbsp;paper&nbsp;size&nbsp;and&nbsp;orientation <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setPaper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'A4'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'portrait'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;the&nbsp;HTML&nbsp;as&nbsp;PDF <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">render<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;canvas&nbsp;instance <br \/><\/span><span style=\"color: #0000BB\">$canvas&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getCanvas<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;font&nbsp;metrics&nbsp;class <br \/><\/span><span style=\"color: #0000BB\">$fontMetrics&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">FontMetrics<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$options<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;height&nbsp;and&nbsp;width&nbsp;of&nbsp;page <br \/><\/span><span style=\"color: #0000BB\">$w&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">get_width<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$h&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">get_height<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;font&nbsp;family&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$font&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$fontMetrics<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getFont<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'times'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;watermark&nbsp;text <br \/><\/span><span style=\"color: #0000BB\">$text&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"CONFIDENTIAL\"<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;height&nbsp;and&nbsp;width&nbsp;of&nbsp;text <br \/><\/span><span style=\"color: #0000BB\">$txtHeight&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$fontMetrics<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getFontHeight<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">75<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$textWidth&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$fontMetrics<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getTextWidth<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">75<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;text&nbsp;opacity <br \/><\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">set_opacity<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">.2<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;horizontal&nbsp;and&nbsp;vertical&nbsp;position <br \/><\/span><span style=\"color: #0000BB\">$x&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;((<\/span><span style=\"color: #0000BB\">$w<\/span><span style=\"color: #007700\">-<\/span><span style=\"color: #0000BB\">$textWidth<\/span><span style=\"color: #007700\">)\/<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$y&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;((<\/span><span style=\"color: #0000BB\">$h<\/span><span style=\"color: #007700\">-<\/span><span style=\"color: #0000BB\">$txtHeight<\/span><span style=\"color: #007700\">)\/<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Writes&nbsp;text&nbsp;at&nbsp;the&nbsp;specified&nbsp;x&nbsp;and&nbsp;y&nbsp;coordinates <br \/><\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">text<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$x<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$y<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">75<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;the&nbsp;generated&nbsp;PDF&nbsp;(1&nbsp;=&nbsp;download&nbsp;and&nbsp;0&nbsp;=&nbsp;preview) <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">stream<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'document.pdf'<\/span><span style=\"color: #007700\">,&nbsp;array(<\/span><span style=\"color: #DD0000\">\"Attachment\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">));<\/span><\/pre>\n<h2>Add Watermark to PDF (image)<\/h2>\n<p>The following example code generates PDF and <b>add watermark image to PDF<\/b> file with Dompdf library using PHP. The process is the same as the text watermark code (above) except for the image setup.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Specify the image path (<code>images\/codexworld-logo.png<\/code>) to which you want to add as a watermark.<\/li>\n<li>Add watermark image to PDF document using <b>image()<\/b> method of Canvas class.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Dompdf&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Options&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Options<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;options&nbsp;to&nbsp;enable&nbsp;embedded&nbsp;PHP <br \/><\/span><span style=\"color: #0000BB\">$options&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Options<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$options<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">set<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'isPhpEnabled'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'true'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;dompdf&nbsp;class <br \/><\/span><span style=\"color: #0000BB\">$dompdf&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$options<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Load&nbsp;HTML&nbsp;content <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">loadHtml<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'&lt;h1&gt;Welcome&nbsp;to&nbsp;CodexWorld.com&lt;\/h1&gt;'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;(Optional)&nbsp;Setup&nbsp;the&nbsp;paper&nbsp;size&nbsp;and&nbsp;orientation <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setPaper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'A4'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'portrait'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;the&nbsp;HTML&nbsp;as&nbsp;PDF <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">render<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;canvas&nbsp;instance <br \/><\/span><span style=\"color: #0000BB\">$canvas&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getCanvas<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;height&nbsp;and&nbsp;width&nbsp;of&nbsp;page <br \/><\/span><span style=\"color: #0000BB\">$w&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">get_width<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$h&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">get_height<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;watermark&nbsp;image <br \/><\/span><span style=\"color: #0000BB\">$imageURL&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'images\/codexworld-logo.png'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$imgWidth&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">200<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$imgHeight&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">20<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;image&nbsp;opacity <br \/><\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">set_opacity<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">.5<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;horizontal&nbsp;and&nbsp;vertical&nbsp;position <br \/><\/span><span style=\"color: #0000BB\">$x&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;((<\/span><span style=\"color: #0000BB\">$w<\/span><span style=\"color: #007700\">-<\/span><span style=\"color: #0000BB\">$imgWidth<\/span><span style=\"color: #007700\">)\/<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$y&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;((<\/span><span style=\"color: #0000BB\">$h<\/span><span style=\"color: #007700\">-<\/span><span style=\"color: #0000BB\">$imgHeight<\/span><span style=\"color: #007700\">)\/<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;an&nbsp;image&nbsp;to&nbsp;the&nbsp;pdf <br \/><\/span><span style=\"color: #0000BB\">$canvas<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">image<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$imageURL<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$x<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$y<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$imgWidth<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$imgHeight<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;the&nbsp;generated&nbsp;PDF&nbsp;(1&nbsp;=&nbsp;download&nbsp;and&nbsp;0&nbsp;=&nbsp;preview) <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">stream<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'document.pdf'<\/span><span style=\"color: #007700\">,&nbsp;array(<\/span><span style=\"color: #DD0000\">\"Attachment\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">));<\/span><\/pre>\n<h2>Watermark Text Configuration<\/h2>\n<p>You can change the position, font size, color, spacing, and rotation (angle) of the watermark text in the PDF. See the available options for the <code>text()<\/code> function of Canvas class.<\/p>\n<pre><span style=\"color: #FF8000\">\/** <br \/>&nbsp;*&nbsp;Writes&nbsp;text&nbsp;at&nbsp;the&nbsp;specified&nbsp;x&nbsp;and&nbsp;y&nbsp;coordinates. <br \/>&nbsp;* <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$x <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$y <br \/>&nbsp;*&nbsp;@param&nbsp;string&nbsp;$text&nbsp;the&nbsp;text&nbsp;to&nbsp;write <br \/>&nbsp;*&nbsp;@param&nbsp;string&nbsp;$font&nbsp;the&nbsp;font&nbsp;file&nbsp;to&nbsp;use <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$size&nbsp;the&nbsp;font&nbsp;size,&nbsp;in&nbsp;points <br \/>&nbsp;*&nbsp;@param&nbsp;array&nbsp;$color <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$word_space&nbsp;word&nbsp;spacing&nbsp;adjustment <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$char_space&nbsp;char&nbsp;spacing&nbsp;adjustment <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$angle&nbsp;angle <br \/>&nbsp;*\/ <br \/><\/span><span style=\"color: #0000BB\">text<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$x<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$y<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$color&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">),&nbsp;<\/span><span style=\"color: #0000BB\">$word_space&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0.0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$char_space&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0.0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$angle&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0.0<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<h2>Watermark Image Configuration<\/h2>\n<p>You can change the position, width, height, and resolution of the watermark image in the PDF. See the available options for the <code>image()<\/code> function of Canvas class.<\/p>\n<pre><span style=\"color: #FF8000\">\/** <br \/>&nbsp;*&nbsp;Add&nbsp;an&nbsp;image&nbsp;to&nbsp;the&nbsp;pdf. <br \/>&nbsp;* <br \/>&nbsp;*&nbsp;The&nbsp;image&nbsp;is&nbsp;placed&nbsp;at&nbsp;the&nbsp;specified&nbsp;x&nbsp;and&nbsp;y&nbsp;coordinates&nbsp;with&nbsp;the <br \/>&nbsp;*&nbsp;given&nbsp;width&nbsp;and&nbsp;height. <br \/>&nbsp;* <br \/>&nbsp;*&nbsp;@param&nbsp;string&nbsp;$img_url&nbsp;the&nbsp;path&nbsp;to&nbsp;the&nbsp;image <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$x&nbsp;x&nbsp;position <br \/>&nbsp;*&nbsp;@param&nbsp;float&nbsp;$y&nbsp;y&nbsp;position <br \/>&nbsp;*&nbsp;@param&nbsp;int&nbsp;$w&nbsp;width&nbsp;(in&nbsp;pixels) <br \/>&nbsp;*&nbsp;@param&nbsp;int&nbsp;$h&nbsp;height&nbsp;(in&nbsp;pixels) <br \/>&nbsp;*&nbsp;@param&nbsp;string&nbsp;$resolution&nbsp;The&nbsp;resolution&nbsp;of&nbsp;the&nbsp;image <br \/>&nbsp;*\/ <br \/><\/span><span style=\"color: #0000BB\">image<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img_url<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$x<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$y<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$w<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$h<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$resolution&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"normal\"<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/\">Add Watermark to Existing PDF using PHP<\/a><\/span><\/p>\n<h2>Conclusion<\/h2>\n<p>This example code can be used to create PDF documents from HTML content dynamically with PHP in the web application. You can customize the generated PDF and <b>add watermark to PDF<\/b> with Dompdf using PHP. Download PDF feature can be provided to <b>export HTML to PDF<\/b> and download as a PDF document on the website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dynamic PDF generation is useful when you want to allow the user to download the text or HTML content in a file on the web application. In this case, the HTML content needs to be <\/p>\n","protected":false},"author":1,"featured_media":5169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[180,179,166,181,14,329],"class_list":["post-4003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-dompdf","tag-html","tag-library","tag-pdf","tag-php","tag-watermark","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Create PDF with Watermark in PHP using Dompdf - CodexWorld<\/title>\n<meta name=\"description\" content=\"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create PDF with Watermark in PHP using Dompdf - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-23T18:30:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T11:02:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Create PDF with Watermark in PHP using Dompdf\",\"datePublished\":\"2019-05-23T18:30:18+00:00\",\"dateModified\":\"2022-11-22T11:02:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/\"},\"wordCount\":587,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png\",\"keywords\":[\"Dompdf\",\"HTML\",\"Library\",\"PDF\",\"PHP\",\"Watermark\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/\",\"name\":\"Create PDF with Watermark in PHP using Dompdf - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png\",\"datePublished\":\"2019-05-23T18:30:18+00:00\",\"dateModified\":\"2022-11-22T11:02:26+00:00\",\"description\":\"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-pdf-with-watermark-in-php-using-dompdf\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create PDF with Watermark in PHP using Dompdf\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create PDF with Watermark in PHP using Dompdf - CodexWorld","description":"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/","og_locale":"en_US","og_type":"article","og_title":"Create PDF with Watermark in PHP using Dompdf - CodexWorld","og_description":"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.","og_url":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2019-05-23T18:30:18+00:00","article_modified_time":"2022-11-22T11:02:26+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Create PDF with Watermark in PHP using Dompdf","datePublished":"2019-05-23T18:30:18+00:00","dateModified":"2022-11-22T11:02:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/"},"wordCount":587,"commentCount":2,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","keywords":["Dompdf","HTML","Library","PDF","PHP","Watermark"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/","url":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/","name":"Create PDF with Watermark in PHP using Dompdf - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","datePublished":"2019-05-23T18:30:18+00:00","dateModified":"2022-11-22T11:02:26+00:00","description":"Add watermark to PDF - Convert HTML to PDF and add watermark text or image using Dompdf and PHP. Example code to create PDF file and add watermark to pdf with Dompdf in PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","width":1366,"height":768,"caption":"create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Create PDF with Watermark in PHP using Dompdf"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2019\/05\/create-pdf-with-watermark-text-image-in-php-using-dompdf-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-12z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=4003"}],"version-history":[{"count":5,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4003\/revisions"}],"predecessor-version":[{"id":5166,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4003\/revisions\/5166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5169"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=4003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=4003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=4003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}