Search code examples
phppdffpdfwatermarkfpdi

How to add watermark to PDF file with PHP and FPDI for Print only?


I am using FPDF and FPDI to add current date to the existing PDF file

$pdf->Cell(0,15, date("Y/m/d"), 0, 0,'R' );

Is it possible to make it visible only when document is printed, something like Set Visibility Print Only?

(Sorry if duplicate, I'm new here)


Solution

  • You can use the script "Visibility" from the script section of FPDF for this purpose. Just change the class so that it extends FPDI:

    class PDF_Visibility extends \setasign\Fpdi\Fpdi 
    { ...
    

    You should know that this does not work for all PDF readers/viewers. Viewers not supporting visibility will show the content throughout.