Hello,
Below is a method to add headers and footers to an existing document.
Please remove all references to Document and PdfCopy (to start with).
There are other problems in your code; most of them can be solved by
cleaning up your code.
It works fine on most document but sometimes, on some pages,
especially if they seem to have been scanned, the header/footer is not
displayed.
It seems to be here because a selection on something invisible can be
performed. There must be a foreground/background issue there but I was
unable to find any clue to make sure the my header/footer are
guaranteed to appear.
You're using a very old version of iText:
import com.lowagie.text.*;
Recent versions use com.itextpdf.text.*
Recent versions contain plenty of bug fixes.
You should upgrade!
You don't need a Document, do you?
Document underdocument = null;
Document overdocument = null;
You only need a PdfStamper and a PdfReader:
PdfStamper pdfstamper = null;
PdfReader reader;
Why do you need undercontent?
Remove:
PdfContentByte undercontent ;
Keep:
PdfContentByte overcontent ;
This is wrong:
underdocument = undercontent.getPdfDocument();
overdocument = overcontent.getPdfDocument();
You need to get the MediaBox or CropBox from the PdfReader object,
NOT from the Document object!
This is also wrong:
fret = pdffooter.writeSelectedRows(0, -1, 0, underdocument.bottom(),
undercontent);
Seems like your adding the footer under the visible area of the page.
Also: add the content on top of the existing content, not under it
(replace undercontent with overcontent).
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText® is a registered trademark of 1T3XT BVBA.
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