{"id":4730,"date":"2021-09-18T06:15:25","date_gmt":"2021-09-18T06:15:25","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=4730"},"modified":"2021-09-18T06:17:23","modified_gmt":"2021-09-18T06:17:23","slug":"add-watermark-to-existing-pdf-using-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/","title":{"rendered":"Add Watermark to Existing PDF using PHP"},"content":{"rendered":"<p>PDF (Portable Document Format) is a popular file format to work with text\/graphics content. Generally, the PDF file is used to share text\/image data for offline use. In the web application, a PDF file is created with HTML content to make dynamic data available for download. We can easily create PDF document dynamically and <a href=\"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/\">convert HTML content to PDF using PHP<\/a>.<\/p>\n<p>In a PDF document, a watermark is used to make it unique by adding text\/image\/stamp over pages. If you using a PHP library such as Dompdf to create PDF document, the watermark can be added at the time of PDF generation. But, in this case, you cannot add a watermark to an existing PDF document. In this tutorial, we will show you how to <b>add watermark to existing PDF document using PHP<\/b>.<\/p>\n<p>In this example script, we will use FPDF and FPDI libraries to add watermark images to PDF with PHP. You can add text or image as a watermark to existing PDF document using PHP.<\/p>\n<h2>Install FPDF and FPDI Library<\/h2>\n<p>Run the following command to install FPDF and FPDI library at once using composer.<\/p>\n<pre>composer require setasign\/fpdi-fpdf<\/pre>\n<p><span class=\"note\">Note that:<\/span> You don&#8217;t need to download the FPDF-FPDI library separately, all the required files are included in the source code.<\/p>\n<p>Include autoloader to load FPDI library and helper functions in the PHP script.<\/p>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Load&nbsp;Fpdi&nbsp;library <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">setasign<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Fpdi<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Fpdi<\/span><span style=\"color: #007700\">; <br \/>require_once(<\/span><span style=\"color: #DD0000\">'vendor\/autoload.php'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<h2>Add Watermark to PDF (text)<\/h2>\n<p>The following example code adds <b>watermark text to the existing PDF<\/b> file using PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Specify source PDF file and watermark text.<\/li>\n<li>Configure text font, weight, and height using PHP <code>imagefontheight()<\/code> and <code>imagefontwidth()<\/code> function.<\/li>\n<li>Create blank image with <code>imagecreatetruecolor()<\/code> function.<\/li>\n<li>Set background and font color with <code>imagecolorallocate()<\/code> function.<\/li>\n<li>Create image with <code>imagepng()<\/code> function.<\/li>\n<li>Initialize Fpdi class and set the source PDF file using <code>setSourceFile()<\/code> method.<\/li>\n<li>Add watermark to PDF pages using <code>importPage()<\/code>, <code>getTemplateSize()<\/code>, <code>addPage()<\/code>, <code>useTemplate()<\/code>, and <code>Image()<\/code> methods of Fpdi class.<\/li>\n<li>Render the generated PDF using the <code>Output()<\/code> function of Fpdi class.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Source&nbsp;file&nbsp;and&nbsp;watermark&nbsp;config <br \/><\/span><span style=\"color: #0000BB\">$file&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'documents\/Proposal.pdf'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$text&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'CodexWorld.com'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Text&nbsp;font&nbsp;settings <br \/><\/span><span style=\"color: #0000BB\">$name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">uniqid<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$font_size&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">5<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$opacity&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$ts&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">explode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\\n\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$width&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>foreach(<\/span><span style=\"color: #0000BB\">$ts&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$k<\/span><span style=\"color: #007700\">=&gt;<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$width&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">max<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">strlen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">)); <br \/>} <br \/><\/span><span style=\"color: #0000BB\">$width&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagefontwidth<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">)*<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$height&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagefontheight<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">)*<\/span><span style=\"color: #0000BB\">count<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$ts<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$el&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagefontheight<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$em&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagefontwidth<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$img&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecreatetruecolor<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Background&nbsp;color <br \/><\/span><span style=\"color: #0000BB\">$bg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecolorallocate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">imagefilledrectangle<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/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\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$bg<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Font&nbsp;color&nbsp;settings <br \/><\/span><span style=\"color: #0000BB\">$color&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecolorallocate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/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\">0<\/span><span style=\"color: #007700\">); <br \/>foreach(<\/span><span style=\"color: #0000BB\">$ts&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$k<\/span><span style=\"color: #007700\">=&gt;<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$len&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">strlen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ypos&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;for(<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">&lt;<\/span><span style=\"color: #0000BB\">$len<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">++){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$xpos&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">*&nbsp;<\/span><span style=\"color: #0000BB\">$em<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ypos&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$k&nbsp;<\/span><span style=\"color: #007700\">*&nbsp;<\/span><span style=\"color: #0000BB\">$el<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">imagechar<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$xpos<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$ypos<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$color<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$string&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/><\/span><span style=\"color: #0000BB\">imagecolortransparent<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$bg<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$blank&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecreatetruecolor<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$tbg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecolorallocate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$blank<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">imagefilledrectangle<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$blank<\/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\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$tbg<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">imagecolortransparent<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$blank<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$tbg<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$op&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$opacity<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$opacity<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">; <br \/>if&nbsp;(&nbsp;(<\/span><span style=\"color: #0000BB\">$op&nbsp;<\/span><span style=\"color: #007700\">&lt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">)&nbsp;OR&nbsp;(<\/span><span style=\"color: #0000BB\">$op&nbsp;<\/span><span style=\"color: #007700\">&gt;<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">)&nbsp;){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$op&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">; <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;watermark&nbsp;image <br \/><\/span><span style=\"color: #0000BB\">imagecopymerge<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$blank<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/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\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$op<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">imagepng<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$blank<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\".png\"<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;source&nbsp;PDF&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$pdf&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Fpdi<\/span><span style=\"color: #007700\">(); <br \/>if(<\/span><span style=\"color: #0000BB\">file_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\".\/\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pagecount&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setSourceFile<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">); <br \/>}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">'Source&nbsp;PDF&nbsp;not&nbsp;found!'<\/span><span style=\"color: #007700\">); <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;watermark&nbsp;to&nbsp;PDF&nbsp;pages <br \/><\/span><span style=\"color: #007700\">for(<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">&lt;=<\/span><span style=\"color: #0000BB\">$pagecount<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">++){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$tpl&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">importPage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$size&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getTemplateSize<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$tpl<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addPage<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">useTemplate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$tpl<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">TRUE<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/Put&nbsp;the&nbsp;watermark <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$xxx_final&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">]-<\/span><span style=\"color: #0000BB\">50<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$yyy_final&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">]-<\/span><span style=\"color: #0000BB\">25<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Image<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'.png'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$xxx_final<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$yyy_final<\/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: #DD0000\">'png'<\/span><span style=\"color: #007700\">); <br \/>} <br \/>@<\/span><span style=\"color: #0000BB\">unlink<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'.png'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;PDF&nbsp;with&nbsp;watermark <br \/><\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Output<\/span><span style=\"color: #007700\">();<\/span><\/pre>\n<h2>Add Watermark to PDF (image)<\/h2>\n<p>The following example code adds a <b>watermark image to an existing PDF<\/b> file using PHP. <\/p>\n<ul class=\"bullet_disk_list\">\n<li>Specify source PDF file and watermark image.<\/li>\n<li>Initialize Fpdi class and set the source PDF file using <code>setSourceFile()<\/code> method.<\/li>\n<li>Add watermark image to PDF pages using <code>importPage()<\/code>, <code>getTemplateSize()<\/code>, <code>addPage()<\/code>, <code>useTemplate()<\/code>, and <code>Image()<\/code> methods of Fpdi class.<\/li>\n<li>Render the generated PDF with watermark using the <code>Output()<\/code> function of Fpdi class.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Source&nbsp;file&nbsp;and&nbsp;watermark&nbsp;config <br \/><\/span><span style=\"color: #0000BB\">$file&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'documents\/Proposal.pdf'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$text_image&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'images\/codexworld-logo.png'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;source&nbsp;PDF&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$pdf&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Fpdi<\/span><span style=\"color: #007700\">(); <br \/>if(<\/span><span style=\"color: #0000BB\">file_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\".\/\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pagecount&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setSourceFile<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">); <br \/>}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">'Source&nbsp;PDF&nbsp;not&nbsp;found!'<\/span><span style=\"color: #007700\">); <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;watermark&nbsp;image&nbsp;to&nbsp;PDF&nbsp;pages <br \/><\/span><span style=\"color: #007700\">for(<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">&lt;=<\/span><span style=\"color: #0000BB\">$pagecount<\/span><span style=\"color: #007700\">;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">++){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$tpl&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">importPage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$size&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getTemplateSize<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$tpl<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addPage<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">useTemplate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$tpl<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">TRUE<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/Put&nbsp;the&nbsp;watermark <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$xxx_final&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">]-<\/span><span style=\"color: #0000BB\">60<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$yyy_final&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">]-<\/span><span style=\"color: #0000BB\">25<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Image<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$text_image<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$xxx_final<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$yyy_final<\/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: #DD0000\">'png'<\/span><span style=\"color: #007700\">); <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;PDF&nbsp;with&nbsp;watermark <br \/><\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Output<\/span><span style=\"color: #007700\">();<\/span><\/pre>\n<h2>Output PDF with Watermark<\/h2>\n<p>By default, the <b>Output()<\/b> method will render the PDF file on the browser. You can use parameters in the <code>Output()<\/code> method to customize the PDF output.<br \/>\n<b>First Parameter:<\/b><\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>I<\/code> &#8211; (default) Output PDF to browser.<\/li>\n<li><code>D<\/code> &#8211; Download PDF file.<\/li>\n<li><code>F<\/code> \u2013 Save PDF to the local file.<\/li>\n<\/ul>\n<p><b>Second Parameter:<\/b><br \/>\nSpecify the file name of the PDF to download.<\/p>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;to&nbsp;browser <br \/><\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Output<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Download&nbsp;PDF&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Output<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'D'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'my-document.pdf'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Save&nbsp;PDF&nbsp;to&nbsp;local&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$pdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Output<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'F'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'my-document.pdf'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/create-pdf-with-watermark-in-php-using-dompdf\/\">Create PDF with Watermark in PHP using Dompdf<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PDF (Portable Document Format) is a popular file format to work with text\/graphics content. Generally, the PDF file is used to share text\/image data for offline use. In the web application, a PDF file is <\/p>\n","protected":false},"author":1,"featured_media":4734,"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":[181,14,329],"class_list":["post-4730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","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>Add Watermark to Existing PDF using PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library 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\/add-watermark-to-existing-pdf-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Watermark to Existing PDF using PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/\" \/>\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=\"2021-09-18T06:15:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-18T06:17:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-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\\\/add-watermark-to-existing-pdf-using-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Add Watermark to Existing PDF using PHP\",\"datePublished\":\"2021-09-18T06:15:25+00:00\",\"dateModified\":\"2021-09-18T06:17:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/\"},\"wordCount\":444,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png\",\"keywords\":[\"PDF\",\"PHP\",\"Watermark\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/\",\"name\":\"Add Watermark to Existing PDF using PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png\",\"datePublished\":\"2021-09-18T06:15:25+00:00\",\"dateModified\":\"2021-09-18T06:17:23+00:00\",\"description\":\"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/add-watermark-to-existing-pdf-using-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Add Watermark to Existing PDF using PHP\"}]},{\"@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":"Add Watermark to Existing PDF using PHP - CodexWorld","description":"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library 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\/add-watermark-to-existing-pdf-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Add Watermark to Existing PDF using PHP - CodexWorld","og_description":"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library in PHP.","og_url":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2021-09-18T06:15:25+00:00","article_modified_time":"2021-09-18T06:17:23+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-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\/add-watermark-to-existing-pdf-using-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Add Watermark to Existing PDF using PHP","datePublished":"2021-09-18T06:15:25+00:00","dateModified":"2021-09-18T06:17:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/"},"wordCount":444,"commentCount":1,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png","keywords":["PDF","PHP","Watermark"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/","url":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/","name":"Add Watermark to Existing PDF using PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png","datePublished":"2021-09-18T06:15:25+00:00","dateModified":"2021-09-18T06:17:23+00:00","description":"Add watermark text or image to existing PDF using PHP. Example code to create PDF file and add watermark to pdf with fpdf and fpdi library in PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png","width":1366,"height":768,"caption":"add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/add-watermark-to-existing-pdf-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Add Watermark to Existing PDF using PHP"}]},{"@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\/2021\/09\/add-watermark-to-existing-pdf-with-fpdf-fpdi-using-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-1ei","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4730","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=4730"}],"version-history":[{"count":3,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4730\/revisions"}],"predecessor-version":[{"id":4733,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4730\/revisions\/4733"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/4734"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=4730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=4730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=4730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}