Hi,
I am getting following error when i try to stamp a footer (page x of y -
where x = current page no & y=total no of pages) on a previously generated
pdf using itext. Problem could be because I m trying to write to the same
file that I am reading. But I dont know how to resolve this. I saw a couple
of posts for the same exception. But there problem was different.
com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not
found.
at com.itextpdf.text.pdf.PRTokeniser.checkPdfHeader(PRTokeniser.java:205)
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:494)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:169)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:158)
my code is as follows:
System.out.println("Report Location: " + getReportLocation() + "\n" +
localPathToReports + fileName);
/*Report Location: C:\CPPDReports\Complete Healthcare Resources\Product Mix
Pie Chart Summary\Master Report - Product Mix Pie Chart Summary (by region)
- Jan 2011 to Nov 2012 (12.07.2012 10.42.59AM).pdf*/
document1 = new Document();
PdfCopy copy = new PdfCopy(document1, new
FileOutputStream(getReportLocation()));
document1.open();
PdfReader reader1 = new PdfReader(getReportLocation());
int n1 = reader1.getNumberOfPages();
PdfImportedPage page;
PdfCopy.PageStamp stamp;
for (int i = 0; i < n1; ) {
page = copy.getImportedPage(reader1, ++i);
stamp = copy.createPageStamp(page);
// add page numbers
ColumnText.showTextAligned(stamp.getUnderContent(),
Element.ALIGN_CENTER,
new Phrase(String.format("page %d of %d", i,
n1)),(document1.right()+document1.rightMargin())/2, document1.bottom() - 26,
0);
stamp.alterContents();
copy.addPage(page);
}
reader1.close();
//copy.close();
document1.close();
copy.close();
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Problem-in-stamping-Page-X-Of-Y-Footer-tp4657100.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) 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