Copying the book code without understanding it won't get you anywhere.
It should be:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfCopyFields copy = new PdfCopyFields(baos);
copy.addDocument(new PdfReader("c:\\coverpage.pdf"));
copy.addDocument(new PdfReader("c:\\BO_INTRO.pdf"));
copy.close();
PdfReader reader = new PdfReader(baos.toByteArray());
baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader,baos);
AcroFields form = stamper.getAcroFields();
form.setField("groupName", "My Group");
stamper.setFormFlattening(true);
// put here your dynamic content (HeaderFooter won't work!)
// see page 57 in the book
stamper.close();
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Tandon, Amrish
> Sent: Friday, January 19, 2007 5:19 PM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] (no subject)
>
> I have based this code from sections 2.3.1 and 2.3.2 of your
> book. Also it would make sense to me if you told me what part
> did not make sense. Also please understand I am new to iText.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Paulo Soares
> Sent: Friday, January 19, 2007 11:49 AM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] (no subject)
>
> Read the tutorial and then tell me from where you got the
> code. It doesn't make sense.
>
> Paulo
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
> > Tandon, Amrish
> > Sent: Friday, January 19, 2007 4:24 PM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] (no subject)
> >
> > Any updates?
> >
> > -----Original Message-----
> > From: Tandon, Amrish
> > Sent: Thursday, January 18, 2007 12:03 PM
> > To: 'Post all your questions about iText here'
> > Subject: RE: [iText-questions] (no subject)
> >
> > Let me clarify.
> >
> > The PdfCopyFields and PdfStamper are working fine. It is everything
> > after the PdfStamper that is using the document to add
> pages and the
> > header/footer that is not doing anything.
> >
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
> > Paulo Soares
> > Sent: Thursday, January 18, 2007 11:52 AM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] (no subject)
> >
> > You have to reinitialize baos before using it in PdfStamper, it was
> > closed in PdfCopyFields.
> >
> > Paulo
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On
> Behalf Of
> > > Tandon, Amrish
> > > Sent: Thursday, January 18, 2007 4:15 PM
> > > To: itext-questions@lists.sourceforge.net
> > > Subject: [iText-questions] (no subject)
> > >
> > > 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();
> > > }
> > >
> > >
> > >
> > >
> > > }
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/