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;
?>
|