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.

Many thanks in advance,
Best regards,
Giovanni 

Document document = new Document(PageSize.A4);
document.newPage();
PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream("letter.pdf"));
document.open();
appendFooter(writer);
document.close();

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 reader = new PdfReader(FOOTER_PATH);
        PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream("temp.pdf"));
        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;
        reader = new PdfReader("temp.pdf");
        PdfImportedPage importedPage = writer.getImportedPage(reader, pageOne);
        PdfContentByte content = writer.getDirectContent();
        content.addTemplate(importedPage, xOffset, yOffset);
}

==============================================================================
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
============================================================================== 
------------------------------------------------------------------------------
Download Intel&#174; 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/

Reply via email to