<cfif NOT isdefined("form.submit")>
<cfform enctype="multipart/form-data">
<strong>PDF*:</strong><cfinput type="file" name="pdfFile" required="yes"><br />
<strong>JPG*:</strong><cfinput type="file" name="jpgFile" required="yes"><br />
New file name:<cfinput type="text" name="newFile"><br />
X:<cfinput type="text" name="x" size="2" validate="integer">/Y:<cfinput type="text" name="y" size="2" validate="integer"><br />
<cfinput type="submit" name="submit" value="submit">
</cfform>
<cfelse>
<!--- Set defualt position --->
<cfif not isnumeric(form.x)>
<cfset form.x = 0>
</cfif>
<cfif not isnumeric(form.y)>
<cfset form.y = 0>
</cfif>
<!--- Upload PDF file --->
<cffile action="upload" destination="#expandpath('.')#" filefield="pdfFile" nameconflict="makeunique">
<cfset pdfFileName = file.ServerFile>
<cfif not len(trim(form.newFile))>
<cfset form.newFile = "#listfirst(pdfFileName,'.')#_signed.pdf">
</cfif>
<!--- Upload JPG file --->
<cffile action="upload" destination="#expandpath('.')#" filefield="jpgFile" nameconflict="makeunique">
<cfset jpgFileName = file.ServerFile>
<CFSCRIPT>
/////////////////////////////////////////////////////////////// // This function applies a jpg watermark to an existing PDF // pdfFile - Relative path to pdf file // jpgFile - Relative path to jpg file // newFile - name of new PDF file // x - horizontal position from bottom left of pdf // y - vertical position from bottom left of pdf //
// Author: Shlomy Gantz //
watermarkPDF(pdfFileName,jpgFileName,form.newFile,form.x,form.y);
function watermarkPDF(pdfFile,jpgFile,newFile,x,y) {
// get original document reader = CreateObject("java", "com.lowagie.text.pdf.PdfReader").init(expandpath(arguments.pdfFile));
// create new document fileIO = CreateObject("java", "java.io.FileOutputStream").init(expandpath(arguments.newFile));
// initiliza stamper stamper= CreateObject("java", "com.lowagie.text.pdf.PdfStamper").init(reader,FileIO);
// create watermark images
Image = CreateObject("java", "com.lowagie.text.Image");
jpg = Image.getInstance(expandpath(arguments.jpgFile));
jpg.setAbsolutePosition(arguments.x, arguments.y);
// stamp all pages with watermark i = 0;
n = reader.getNumberOfPages();
while (i lt n) {
i=i+1;
b = stamper.getUnderContent(javacast("Int",i));
b.addImage(jpg);
}
stamper.close();
}
</CFSCRIPT>
<cfoutput>
<a href="#form.newFile#">Click here to download the signed PDF</a>
</cfoutput>
</cfif>
[cod edit] Use Code tags!
This post has been edited by snoj: 14 October 2007 - 11:28 AM

New Topic/Question
Reply




MultiQuote



|