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!
PHP Watermark Sample |
Post Reply |
Author | |
Jimeni
Beginner Joined: 09 Apr 10 Status: Offline Points: 10 |
Post Options
Thanks(0)
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store