Following is a code snippet creating a pdf file where pages could be rotated in the resulting file. This works fine for most pdf files. But one particualr pdf file of version 1.6 the page is already rotated by 180, on applying further rotation to it e.g. 90 degress and saving the file causes it to get corrupted. Infact even if you don't rotate the file and simply write it out to another file using iText the file the resulting pdf is corrupted and displays an out of memory exception when opened in Adobe reader.
Why would that happen? Am I missing some sort of compression in the file. private String createPdfFileWithoutForms(final EditStateData[] editStateData, final String directory) throws EditingException { Long startTime = System.currentTimeMillis(); File pdfFileToReturn = new File(directory + File.separator + UidGenerator.generate() + ".pdf"); com.lowagie.text.Document document = null; FileOutputStream outputStream = null; PdfCopy pdfCopy = null; PdfReader reader = null; PdfDictionary pageDict = null; int rotationAngle = 0; Map<Integer, Integer> rotationQuadrants = null; try { document = new com.lowagie.text.Document(); outputStream = new FileOutputStream(pdfFileToReturn); pdfCopy = new PdfCopy(document, outputStream); pdfCopy.setFullCompression(); pdfCopy.setCompressionLevel(9); document.open(); for (EditStateData state : editStateData) { try { reader = new PdfReader(state.getFileName()); reader.selectPages(state.getPages()); rotationQuadrants = state.getRotationQuadrants(); for (int i = 1; i <= reader.getNumberOfPages(); i++) { // Rotation quadrant key is the source page number if (rotationQuadrants.containsKey(state.getPages().get(i - 1))) { rotationAngle = reader.getPageRotation(i); pageDict = reader.getPageN(i); pageDict.put(PdfName.ROTATE, new PdfNumber((rotationAngle + rotationQuadrants.get(state.getPages().get(i - 1))) % 360)); } document.setPageSize(reader.getPageSizeWithRotation(i)); document.newPage(); // import the page from source pdf PdfImportedPage page = pdfCopy.getImportedPage(reader, i); // add the page to the destination pdf pdfCopy.addPage(page); } } catch (final IOException e) { LOGGER.error(e.getMessage(), e); throw new EditingException(e.getMessage(), e); } finally { if (reader != null) { reader.close(); } } } } catch (final Exception e) { LOGGER.error(e.getMessage(), e); throw new EditingException(e.getMessage(), e); } finally { if (document != null) { document.close(); } if (pdfCopy != null) { pdfCopy.close(); } IoUtils.closeQuietly(outputStream); } LOGGER.debug("Combining " + editStateData.length + " pdf files took " + ((System.currentTimeMillis() - startTime) / 1000) + " msecs"); return pdfFileToReturn.getAbsolutePath(); } -- View this message in context: http://itext-general.2136553.n4.nabble.com/iText-pdf-rotation-resulting-PDF-displays-out-of-memory-in-adobe-tp4658565.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ 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