Hey guys, I saw an entry or two online about this particular need, but no
easily-understandable solutions.
Here's what I have:
I've used Cold Fusion's CFPDF to take an AJAX/CF form and create a PDF....I
now need to merge that PDF with a few other pre-existing interactive PDF's
(which is why I have to use iText and not CFPDF's merge action).
I have this working without a problem...the issue is that I need this merged
PDF to output to the browser (not converted into HTML, just opening the PDF)
WITHOUT writing the PDF file to the server.
Here is the code that merges and creates the PDF file now (final.pdf for
testing purposes):
<cfscript>
savedErrorMessage = "";
// by default outputs to current directory. change as needed
fullPathToOutputFile = ExpandPath("./final.pdf");
// step 1: creation of a document-object
document = createObject("java", "com.lowagie.text.Document").init();
if ('#session.packettype#' EQ 'NLV')
{
arrayOfInputFiles = arrayNew(1);
arrayAppend(arrayOfInputFiles, ExpandPath("./page1.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/nlv_lpfeechart.pdf"));
arrayAppend(arrayOfInputFiles, ExpandPath("./page2.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/nlv_affidavit.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/nlv_certapp.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/nlv_checklist.pdf"));
}
else if ('#session.packettype#' EQ 'LV')
{
arrayOfInputFiles = arrayNew(1);
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_checklist.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_regfee_exemption.pdf"));
}
else if ('#session.packettype#' EQ 'M')
{
arrayOfInputFiles = arrayNew(1);
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_checklist.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_regfee_exemption.pdf"));
}
else if ('#session.packettype#' EQ 'B')
{
arrayOfInputFiles = arrayNew(1);
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_checklist.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_regfee_exemption.pdf"));
}
else if ('#session.packettype#' EQ 'MH')
{
arrayOfInputFiles = arrayNew(1);
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_checklist.pdf"));
arrayAppend(arrayOfInputFiles,
ExpandPath("./includes/mil_regfee_exemption.pdf"));
}
else {
}
try { pageOffset = 0;
PdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader");
SimpleBookmark = createObject("java",
"com.lowagie.text.pdf.SimpleBookmark");
// cfSearching: Internally CF stores arrays as Vectors. So I chose to use an
explict vector
// cfSearching: here, but you could use an array and CF array functions
instead
allBookmarks = createObject("java", "java.util.Vector");
for ( fileIndex = 1; fileIndex LTE arrayLen(arrayOfInputFiles); fileIndex =
fileIndex + 1) {
// we create a reader for a certain document
reader = pdfReader.init( arrayOfInputFiles[fileIndex] );
reader.consolidateNamedDestinations();
// we retrieve the total number of pages
totalPages = reader.getNumberOfPages();
bookmarks = SimpleBookmark.getBookmark(reader);
if (IsDefined("bookmarks")) {
if (pageOffset neq 0) {
SimpleBookmark.shiftPageNumbers(bookmarks, javacast("int", pageOffset),
javacast("null", 0));
}
allBookmarks.addAll(bookmarks);
}
pageOffset = pageOffset + totalPages;
if (fileIndex EQ 1) {
// step 1: creation of a document-object
document = createObject("java", "com.lowagie.text.Document");
document = document.init( reader.getPageSizeWithRotation( javacast("int",
1)) );
// step 2: we create a writer that listens to the document
outStream = createObject("java", "java.io.FileOutputStream").init(
fullPathToOutputFile );
pdfWriter = createObject("java",
"com.lowagie.text.pdf.PdfCopy").init(document, outStream);
// step 3: we open the document
document.open(); }
// step 4: we add content
for (pageIndex = 1; pageIndex LTE totalPages; pageIndex = pageIndex + 1) {
page = pdfWriter.getImportedPage(reader, javacast("int", pageIndex) );
pdfWriter.addPage(page);
}
formFields = reader.getAcroForm();
if (IsDefined("formFields")) {
pdfWriter.copyAcroForm(reader);
}
}
if (NOT allBookmarks.isEmpty()) {
pdfWriter.setOutlines( allBookmarks );
}
// step 5: we close the document
document.close();
WriteOutput("Finished!");
}
catch (java.language.Exception de) {
savedErrorMessage = de; }
// cfSearching: close document and output stream objects if
(IsDefined("document")) {
document.close();
if (IsDefined("outputStream")) {
outputStream.close(); }
</cfscript>
I see examples of how to output a file to the browser, but they seem to use
different writing methods than I have (maybe because of the merge)....I
managed to piece this together from online examples, so I have no idea where
to start on making this display to the browser instead of writing a file.
Thanks in advance for any help!!
Tim
--
View this message in context:
http://www.nabble.com/PDF-Merge---Output-to-screen%2C-not-File%2C-CFSCRIPT-tp26084617p26084617.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/