Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created November 18, 2014 17:54
Show Gist options
  • Select an option

  • Save JamoCA/add773f811bcb40cf06c to your computer and use it in GitHub Desktop.

Select an option

Save JamoCA/add773f811bcb40cf06c to your computer and use it in GitHub Desktop.
Using ColdFusion & iText to merge PDFs with editable forms
<cfscript>
/* Using ColdFusion and iText to merge PDFs with editable forms.
Adobe apparently doesn't allow this due to licensing reasons.
If merged using solely CFPDF, only the last merged PDF document will have editable fields.
NOTE: Any merged editeable fields with duplicate fieldnames will result in being bound together when edited.
CREDIT ~2007: http://cfsearching.blogspot.com/2007/12/getting-started-with-itext-part-18.html
*/
inFiles = ["c:\file1.pdf", "c:\file2.pdf", "c:\file3.pdf", "c:\file4.pdf"];
outFile = "c:\merged.pdf";
try {
outStream = createObject("java", "java.io.FileOutputStream").init( outFile );
copy = createObject("java", "com.lowagie.text.pdf.PdfCopyFields").init(outStream);
PdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader");
for (inFile in inFiles) {
reader = PdfReader.init( inFile );
copy.addDocument(reader);
}
WriteOutput("Finished!");
}
catch (java.language.Exception de) {
writedump(de);
}
if (IsDefined("copy")) {
copy.close();
}
if (IsDefined("outputStream")) {
outputStream.close();
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment