<?php
require_once __DIR__ . '/fpdf/fpdf.php';
require_once __DIR__ . '/FPDI/src/autoload.php';
function addWatermark($x, $y, $watermarkText, $angle, $pdf)
{
$angle = $angle * M_PI / 180;
$c = cos($angle);
$s = sin($angle);
$cx = $x * 1;
$cy = (300 - $y) * 1;
$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, - $s, $c, $cx, $cy, - $cx, - $cy));
$pdf->Text($x, $y, $watermarkText);
$pdf->_out('Q');
}
$pdf = new setasignFpdiFpdi();
$fileInput = 'example.pdf';
$pages_count = $pdf->setSourceFile($fileInput);
for ($i = 1; $i <= $pages_count; $i ++) {
$pdf->AddPage();
$tplIdx = $pdf->importPage($i);
$pdf->useTemplate($tplIdx, 0, 0);
$pdf->SetFont('Times', 'B', 70);
$pdf->SetTextColor(192, 192, 192);
$watermarkText = 'CONFIDENTIAL';
addWatermark(105, 220, $watermarkText, 45, $pdf);
$pdf->SetXY(25, 25);
}
$pdf->Output();
?>
<?php
require __DIR__ . '/fpdf/fpdf.php';
class PDF extends FPDF
{
function Header()
{
// setting the font, color and text for watermark
$this->SetFont('Times', 'B', 48);
$this->SetTextColor(140, 180, 205);
$watermarkText = 'New PDF Watermark - PHP';
$this->addWatermark(35, 190, $watermarkText, 45);
}
function addWatermark($x, $y, $watermarkText, $angle)
{
$angle = $angle * M_PI / 180;
$c = cos($angle);
$s = sin($angle);
$cx = $x * $this->k;
$cy = ($this->h - $y) * $this->k;
$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, - $s, $c, $cx, $cy, - $cx, - $cy));
$this->Text($x, $y, $watermarkText);
$this->_out('Q');
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);
$pdfDocumentContent = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. .
";
for ($i = 0; $i < 15; $i ++) {
$pdf->MultiCell(0, 5, $pdfDocumentContent, 0, 'J');
}
$pdf->Output();
?>