Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - PHP Watermark Sample
  FAQ FAQ  Forum Search   Register Register  Login Login

PHP Watermark Sample

 Post Reply Post Reply
Author
Message
Jimeni View Drop Down
Beginner
Beginner
Avatar

Joined: 09 Apr 10
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jimeni Quote  Post ReplyReply Direct Link To This Post Topic: PHP Watermark Sample
    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;


?>


Edited by Jimeni - 09 Apr 10 at 6:56AM
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store