Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Add a watermark to an existing PDF document

<?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();
?>
Comment

Add a watermark to a new PDF document

<?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();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php auto reset score 
Php :: wordpress php 
Php :: php to display variables 
Php :: codeigniter admin panel with crud generator - 
Php :: registerd navigations file uploadid 
Php :: membership_registration: city or town 
Php :: another query to get user details 
Php :: check if product has crosssell woocommerce 
Php :: how to import Yomo in larave; 
Php :: how to sum values of two product which are same gst rate and this product are come from foreach loop in php 
Php :: What does this mean in PHP: - or = 
Php :: laravel 7 link to another page with language prefix 
Php :: php server on local machine 
Php :: call stored procedure in laravel 
Php :: php limit results by 30 days 
Php :: Unable to open sqlite DB file from js axios.get request 
Php :: import data from csv laravel 
Php :: get_user_info 
Php :: integracao de webservice no php usando soap 
Php :: how to put external file in laravel listener class 
Php :: add object to http request php behamin proxy bproxy 
Php :: phpmailer 5 string attachment 
Php :: difference between guard and fillable laravel 
Php :: get header sent var 
Php :: laravel save or post 
Php :: $request laravel undefined inside function query 
Php :: update php version of particular domain on ubuntu 
Php :: sage theme get template 
Php :: wp $product add alt 
Php :: open two files at once in phpstrom 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =