Hi All 

Have written some code using itext framework to write a footer to each page
in a PDF. 

String origninalPdf = "test.pdf";
String outputPdf = "test-stamped.pdf";
String text "hello from me";

PdfReader reader = new PdfReader(originalPdf);
            
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream(outputPdf));
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.EMBEDDED);
int total = reader.getNumberOfPages();

for (int i = 1; i <= total; i++) {
Rectangle rectangle = reader.getPageSize(i);
float pageHeight = rectangle.getHeight();
float pageWidth = rectangle.getWidth();
PdfContentByte over = stamper.getOverContent(i);
over.beginText();
float fontSize = getFontSize();
over.setFontAndSize(bf, fontSize);

float stringWidth = over.getEffectiveStringWidth(text, false);
float x = getXPostition(pageWidth, stringWidth);
float y = getYPostition(pageHeight);

over.setTextMatrix(x, y);
over.showText(text);
over.endText();
}

stamper.close();
reader.close();

The problem i am having is. The code works fine on the PDF's i create using
Open Office and some other ones i have eg (the itext in action book) . I run
my code and open the file in a reader and can see my footer.

However it does NOT work for other PDF's.

Can anyone tell me why PdfStamper would not work under some circumstances eg
(security issues, permissions, pdf versions etc) 

Can i get it throw an error if it failed to work.

many regards in advance Pete
-- 
View this message in context: 
http://www.nabble.com/PdfStamper-not-working-on-some-PDF%27s-tp19069979p19069979.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to