Hi All,

I am stuck with adding a Header and Footer to an existing PDF.

Any clues are appreciated. I have already checked the iText Documentation and 
did not find anything matching.
 
My code goes like below -
 
Document document = new Document();
    try {
        // step 2:
        FileInputStream is = new FileInputStream("D://2.pdf");
        int nRead;
        byte[] data = new byte[16384];
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        while ((nRead = is.read(data, 0, data.length)) != -1) {
          buffer.write(data, 0, nRead);           
        }

        buffer.flush();
        PdfWriter writer = PdfWriter.getInstance(document,buffer);
        writer.setPageEvent(new HeaderFooter());
        // step 3:
        document.open();

        document.add( new Chunk("testing")); 

    } catch (Exception de) {
        de.printStackTrace();
    } 
    finally{
        document.close();
    }
 
If I comment the line
 
document.add( new Chunk("testing"));
 
I get an exception
 
Exception in thread "main" ExceptionConverter: java.io.IOException: The 
document 
has no pages.
 
Without commenting there are no exceptions but it doesnt add the Header and 
Footer. Any clues are highly appreciated.
 
Or if you could suggest how can I add events to an existing PDF.
I also tried using PDFCopy and adding events to it but seems like you can 
attach 
events only to a writer.

Is there anyways we can add header and footer to an existing PDF?

Regards,
Tina Agrawal


      

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to