This is actually 2 related questions (I have the book "iText in Action"
as well as the tutorial, but am still scratching my head and am hoping
someone more familiar with iText has some pointers)...
Question 1:
==================================================
I am having difficulty figuring out how to use a template pdf file when
creating a new document from scratch.
I am trying to create a new pdf file, say "longText.pdf", with some
arbitrarily long text.
Each page should have some pre-defined "boilerplate" text, and some form
fields (the output "longText.pdf" will be later appended to a multi-page
template, and the resulting pdf will be stamped with data).
I have an existing single page template, say "longTextTemplate.pdf"
which has the boilerplate text and form fields which should appear on
every page of the output "longText.pdf".
I create the Document, get a PdfWriter (using getInstance()).
I define a PdfPageEvent (by extending PdfPageEventHelper) and add this
to the PdfWriter.
The onEndPage method is as follows:
public void onEndPage(PdfWriter writer, Document document) {
if ( templatePage == null ) {
templatePage = writer.getImportedPage(templateReader,1);
}
PdfContentByte cb = writer.getDirectContent();
cb.addTemplate(templatePage,0f,0f);
}
I add the text to the document, and as documented, the boilerplate text
from "longTextTemplate.pdf" shows up fine on every page of the output,
but no form fields.
I understand that with PdfStamper the form fields would be included as
well, but am not sure how to bring PdfStamper into the process.
I am hoping to do as much in memory as possible, rather than writing too
many temporary files.
Question 2:
==================================================
This is part of a larger process, and if anyone has any suggestions on a
better way to do this, I would be grateful.
Here is the larger scenario:
We have a 5 page template with form fields.
I produce an xfdf data file and currently merge this using fdfmerge from
appligent.
The last page of the template, however, has a large multi-line form
field.
Until recently the text could easily fit in this field.
Now, however, the text for this field can require several pages.
So here's how I have been trying to go about it:
1) I have split the 5 page template into 2 templates --
one with pages 1-4 ("mainTemplate.pdf")
and the other with only page 5 ("longTextTemplate.pdf")
2) At runtime, I create a new document with the long text.
Margins are defined big enough to accommodate the boilerplate text
and form fields from the "longTextTemplate.pdf".
On every page, add the contents (text and form fields)
from "longTextTemplate.pdf"
3) append (using PdfCopyFields) the output from step 2 "longText.pdf"
to "mainTemplate.pdf" to produce "combinedTemplate.pdf".
This will have the contents of "mainTemplate.pdf"
followed by the contents of "longText.pdf"
4) use PdfStamper to fill and flatten the fields
in "combinedTemplate.pdf" with the field values
in the xfdf data file to produce the final output.
Do these steps seem reasonable?
If so, I have it working other than the fact that the form fields
defined in "longTextTemplate.pdf" are not showing up (because I am using
PdfWriter to add the PdfImportedPage (using addTemplate()).
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/