i am creating a pdf using itext and numbering using pdfstamper. then i insert a scanned image using acrobat writer in the pdf document i have created using itext. the page number are incorrect. please help me how to get the ordered page numbers
i creating a pdf document using itext and inserted the page numbers. the user take the soft copy and pdf document and insert a scanned page using acrobat writer. by the time the page number should be rearranged accordingly. but it not happen in my case. because i am writing the page number in pdf document using pdfstamper like
showTextAligned(PdfContentByte.ALIGN_LEFT, "Page " + i + " of " + n, x, 5, 0);
the code to write page number
reader = new PdfReader(baos.toByteArray());
reader.makeRemoteNamedDestinationsLocal();
baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
PdfContentByte cb;
int n = reader.getNumberOfPages();
for (int i = 1; i <= n; i++) {
cb = stamper.getOverContent(i);
float x = cb.getPdfDocument().getPageSize().getWidth() / 2;
if (cb.getPdfDocument().getPageSize().equals(
PageSize.A4.rotate())) {
x = x + 150;
}
else if(cb.getPdfDocument().getPageSize().equals(
PageSize.A4)){
//Condition to check if the page is rotated - If rotated then page number should be adjusted acc to the height
if(reader.getPageRotation(i)==90){
x = cb.getPdfDocument().getPageSize().getHeight()/2 - 50;
}
else{
x = x - 50;
}
}
cb.beginText();
cb.setFontAndSize(bf, 10);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "Page " + i
+ " of " + n, x, 5, 0);
cb.endText();
}
stamper.close();
North America
Europe, Middle East and Africa
Asia Pacific