Print Page | Close Window

PHP Watermark Sample

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1406
Printed Date: 22 Nov 24 at 7:05PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: PHP Watermark Sample
Posted By: Jimeni
Subject: PHP Watermark Sample
Date Posted: 09 Apr 10 at 6:55AM
This is probably not the cleanest example but there is a lack of PHP examples about so it might be useful.
It takes paremeters from a form and collects the variables passed and adds the required watermark to all pages of the PDF.

<?php

/*
$Watermark = "Watermark Text";
$EPCN = "Extra Text bottom right";
$FilePath = "C:\AM4370_1_0.pdf";
*/

$Watermark = $_REQUEST['TextStamp'];

$EPCN = $_REQUEST['EPCN'];

$FilePath = $_REQUEST['FilePath'];

$OutputPath = $_REQUEST['OutputPath'];



$qp = new COM("QuickPDFAX0718.PDFLibrary");
$validKey = $qp->UnlockKey("YourKey");



$qp->SetMeasurementUnits(1); /* Set as measured in mm */
echo $r = $qp->LoadFromFile($FilePath);

$intPageCount = 1;
for ( $qp->SelectPage($intPageCount); $intPageCount <= $qp->PageCount; $intPageCount ++) { /* Loop through all pages in doc */
    $qp->SelectPage($intPageCount);
   
    $pageheight  = $qp->PageHeight;
    $pagewidth = $qp->PageWidth;
   
    $myheight = (($pageheight/2) - ($pageheight * .05)); /* Define center - 5% of height to accomodate angle */
    $mywidth = ($pagewidth/2);
    $WatermarkSize = ( ($myheight + $mywidth) / strLen($Watermark) ); /* This should calc the correct text size relative to the document and amount of text */
    $EPCNTextSize = ( ($myheight + $mywidth) / 60 );
   
    $qp->SetTextAlign(1);/* Align text center */
   
   
   
   
    $qp->SetTransparency(70);
    $qp->SetTextSize($WatermarkSize);
    echo $r = $qp->DrawRotatedText($mywidth, $myheight, 45, $Watermark); /* Draw Watermark at center */
    $qp->SetTextAlign(2); /* Align text right */
   
    $qp->SetTransparency(0);
    $qp->SetTextSize($EPCNTextSize);
    echo $r = $qp->DrawText($pagewidth -20, 1, "Open EPCN Number: " . $EPCN); /* Draw EPCN at bottom right with 20 padding */

}

$result = $qp->SaveToFile($OutputPath);
if ($result == 1)
{
    header("Location: /Output/MyTest2.pdf"); /* Forward the browser straight to the generated PDF */
}
else
{
    echo "File could not be saved to disk.";
    echo "<br /><br />";
}
$qp = null;


?>



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk