List of usage examples for com.itextpdf.text.pdf PdfReader getPageRotation
int getPageRotation(final PdfDictionary page)
From source file:org.sejda.impl.itext5.component.AbstractPdfCopier.java
License:Open Source License
public void addBlankPage(PdfReader reader) throws TaskException { try {/*ww w. j a va 2s . co m*/ pdfCopy.addPage(reader.getPageSize(1), reader.getPageRotation(1)); numberOfCopiedPages++; } catch (DocumentException e) { throw new TaskException("Unable to add blank page.", e); } }
From source file:oscar.dms.IncomingDocUtil.java
License:Open Source License
public static void rotatePage(String queueId, String myPdfDir, String myPdfName, String MyPdfPageNumber, int degrees) throws Exception { long lastModified; String filePathName, tempFilePathName; int rot;/*from w ww . ja v a 2s .co m*/ int rotatedegrees; tempFilePathName = getIncomingDocumentFilePath(queueId, myPdfDir) + File.separator + "T" + myPdfName; filePathName = getIncomingDocumentFilePathName(queueId, myPdfDir, myPdfName); File f = new File(filePathName); lastModified = f.lastModified(); PdfReader reader = null; PdfStamper stp = null; try { reader = new PdfReader(filePathName); rot = reader.getPageRotation(Integer.parseInt(MyPdfPageNumber)); rotatedegrees = rot + degrees; rotatedegrees = rotatedegrees % 360; reader.getPageN(Integer.parseInt(MyPdfPageNumber)).put(PdfName.ROTATE, new PdfNumber(rotatedegrees)); stp = new PdfStamper(reader, new FileOutputStream(tempFilePathName)); } catch (Exception e) { throw (e); } finally { try { if (stp != null) { stp.close(); } if (reader != null) { reader.close(); } } catch (Exception e) { throw (e); } } boolean success = f.delete(); if (success) { File f1 = new File(tempFilePathName); f1.setLastModified(lastModified); success = f1.renameTo(new File(filePathName)); if (!success) { throw new Exception("Error in renaming file from:" + tempFilePathName + " to " + filePathName); } } else { throw new Exception("Error in deleting file:" + filePathName); } }
From source file:oscar.dms.IncomingDocUtil.java
License:Open Source License
public static void rotateAlPages(String queueId, String myPdfDir, String myPdfName, int degrees) throws Exception { long lastModified; String filePathName, tempFilePathName; int rot;/*from w ww. j av a 2 s . c o m*/ int rotatedegrees; tempFilePathName = getIncomingDocumentFilePath(queueId, myPdfDir) + File.separator + "T" + myPdfName; filePathName = getIncomingDocumentFilePathName(queueId, myPdfDir, myPdfName); File f = new File(filePathName); lastModified = f.lastModified(); PdfReader reader = null; PdfStamper stp = null; try { reader = new PdfReader(filePathName); for (int p = 1; p <= reader.getNumberOfPages(); ++p) { rot = reader.getPageRotation(p); rotatedegrees = rot + degrees; rotatedegrees = rotatedegrees % 360; reader.getPageN(p).put(PdfName.ROTATE, new PdfNumber(rotatedegrees)); } stp = new PdfStamper(reader, new FileOutputStream(tempFilePathName)); } catch (Exception e) { throw (e); } finally { try { if (stp != null) { stp.close(); } if (reader != null) { reader.close(); } } catch (Exception e) { throw (e); } } boolean success = f.delete(); if (success) { File f1 = new File(tempFilePathName); f1.setLastModified(lastModified); success = f1.renameTo(new File(filePathName)); if (!success) { throw new Exception("Error in renaming file from:" + tempFilePathName + "to " + filePathName); } } else { throw new Exception("Error in deleting file:" + filePathName); } }