Hello all.

I need help! I am trying to use iText to build a PDF composed of several
other PDFs.and then add some dynamic content.  The code below is what I
have so far. It does not seem to take the page additions and the header
and footers. 


                protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException 
        {
                
                try {
                        
                        
                        ByteArrayOutputStream baos = new
ByteArrayOutputStream();
                        
                        //concatinate documents
                        
                        PdfCopyFields copy = new PdfCopyFields(baos);
                        copy.addDocument(new
PdfReader("c:\\coverpage.pdf"));
                        copy.addDocument(new
PdfReader("c:\\BO_INTRO.pdf"));
                        copy.close();
                        
                        //Update form field(s)
                        
                        PdfReader reader = new
PdfReader(baos.toByteArray());
                        PdfStamper stamper = new
PdfStamper(reader,baos);
                        AcroFields form = stamper.getAcroFields();
                        form.setField("groupName", "My Group");
                        stamper.setFormFlattening(true);
                        stamper.close();
                        
                        reader = new PdfReader(baos.toByteArray());     
                        
                        //Add dynamic content.
                        
                        Document document = new
Document(reader.getPageSizeWithRotation(1));
                        document.open();
                
                        document.newPage();
                        document.add(new Paragraph("Hello World"));
                        document.add(new Paragraph(new
Date().toString()));
                        document.newPage();
                        document.add(new Paragraph("Hello World
Again"));
                        document.add(new Paragraph(new
Date().toString()));
                        
                        //Add header and footer
                        document.setHeader(new HeaderFooter(new
Phrase("This is a header"),false));
                        document.setFooter(new HeaderFooter(new
Phrase("This is a footer"),true));
                        document.close();
                        
                        response.setHeader("Expires", "0");
                        response.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
                        response.setHeader("Pragma", "public");
                        response.setContentType("application/pdf");
                        response.setContentLength(baos.size());
                        ServletOutputStream out =
response.getOutputStream();
                        baos.writeTo(out);
                        out.flush();
                } catch (DocumentException e) {
                        e.printStackTrace();
                } 
                
                
                
                
        }


Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate 
companies are not responsible for errors or omissions in this e-mail message. 
Any personal comments made in this e-mail do not reflect the views of Blue 
Cross Blue Shield of Florida, Inc.  The information contained in this document 
may be confidential and intended solely for the use of the individual or entity 
to whom it is addressed.  This document may contain material that is privileged 
or protected from disclosure under applicable law.  If you are not the intended 
recipient or the individual responsible for delivering to the intended 
recipient, please (1) be advised that any use, dissemination, forwarding, or 
copying of this document IS STRICTLY PROHIBITED; and (2) notify sender 
immediately by telephone and destroy the document. THANK YOU.
-------------------------------------------------------------------------
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/

Reply via email to