Hello,
Thank you. I searched the book for "ByteArrayOutputStream" and found the
solution.
Now I don't need to use a temp file:
private static void appendFooter(PdfWriter writer) throws Exception {
Map<String, String> replacements = new HashMap<String, String>();
replacements.put("ph0001", "Juan Perez");
replacements.put("ph0002", "Head of Customer Acquisition");
replacements.put("ph0003", "Dayana Gonzales");
replacements.put("ph0004", "Head of Customer Satisfaction");
PdfReader footerReader = new PdfReader(FOOTER_PATH);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(footerReader, outputStream);
AcroFields form = stamper.getAcroFields();
for (Map.Entry<String, String> entry : replacements.entrySet()) {
form.setField(entry.getKey(), entry.getValue());
}
stamper.setFormFlattening(true);
stamper.close();
int pageOne = 1;
int xOffset = 0;
int yOffset = -550;
PdfReader memoryReader = new PdfReader(outputStream.toByteArray());
PdfImportedPage importedPage = writer.getImportedPage(memoryReader, pageOne);
PdfContentByte content = writer.getDirectContent();
content.addTemplate(importedPage, xOffset, yOffset);
}
Best regards,
Giovanni
-----Original Message-----
From: 1T3XT info [mailto:[email protected]]
Sent: Wednesday, March 24, 2010 11:39 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] avoid create temp.pdf file
Azùa Giovanni (KSXD 32) wrote:
> Hello,
>
> Is there any way to avoid creating a temp.pdf file for implementing the
> use-case below? Basically I need to create a letter.pdf document by
> loading and combining many small "template parts" the template parts may
> need (as in the case depicted below) to be populated and flattened first.
Please read the book.
It explains that you can write PDF to any OutputStream.
Why are you using a FileOutputStream, if you want to write
the PDF to memory? Use a ByteArrayOutputStream instead.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
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/
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
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/