Hi, I'm trying to paginate a pdf but there are some pages that are beeing inverted and i don´t realise the cause. I've tried two solutions, but both have downsides. The first one, i created a new Document, i used PdfWriter to write the text, i wrapped the PdfImportedPage in an Image object, i scaledthe image object, and finally i added it to the new document. My problem is the unwanted inversion. In second solution, i used PdfStamper to add the content to my pdf. It didn't invert my pages but i can´t normalize the pages size to A4 and it´s necessary. I tested many versions of itext, including the newest 5.3.5. I´m uploading a pdf sample that is inverting and a snap code. Could you help resolve this problem ?
Regards input.pdf <http://itext-general.2136553.n4.nabble.com/file/n4657177/input.pdf> public static void solution1() throws IOException, DocumentException { PdfReader reader = new PdfReader(inputFile); int totalPages = reader.getNumberOfPages(); Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile1)); document.open(); PdfContentByte directContent = writer.getDirectContent(); for (int pageNumber = 1; pageNumber <= totalPages; pageNumber++) { PdfImportedPage page = writer.getImportedPage(reader, pageNumber); Image image = Image.getInstance(page); image.scaleAbsolute(PageSize.A4.getWidth(), PageSize.A4.getHeight()); image.setAbsolutePosition(0, 0); directContent.addImage(image); paginate(pageNumber, totalPages, directContent); document.newPage(); } document.close(); } public static void solution2() throws IOException, DocumentException { PdfReader reader = new PdfReader(inputFile); int totalPages = reader.getNumberOfPages(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile2)); for (int pageNumber = 1; pageNumber <= totalPages; pageNumber++) { PdfContentByte directContent = stamper.getOverContent(pageNumber); paginate(pageNumber, totalPages, directContent); } stamper.close(); } private static void paginate(int pageNumber, int totalPages, PdfContentByte cb) { try { BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); StringBuilder text = new StringBuilder().append(pageNumber).append(" / ").append(totalPages); cb.beginText(); cb.setFontAndSize(font, 9f); cb.setTextMatrix(540f, 15f); cb.showText(text.toString()); cb.endText(); } catch (Exception ex) { throw new RuntimeException(ex); } } -- View this message in context: http://itext-general.2136553.n4.nabble.com/Invertion-of-pages-tp4657177.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 iText-questions@lists.sourceforge.net 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