/** @see com.lowagie.tools.AbstractTool#execute() */ public static void execute(String srcvalue, String destvalue, String rotvalue) { try { if (StringUtils.isBlank(srcvalue)) { throw new InstantiationException("You need to choose a sourcefile"); } File src = new File(srcvalue); if (StringUtils.isBlank(destvalue)) { throw new InstantiationException("You need to choose a destination file"); } File dest = new File(destvalue); if (StringUtils.isBlank(rotvalue)) { throw new InstantiationException("You need to choose a rotation"); } int rotation = Integer.parseInt(rotvalue); // we create a reader for a certain document PdfReader reader = new PdfReader(src.getAbsolutePath()); // we retrieve the total number of pages and the page size int total = reader.getNumberOfPages(); System.out.println("There are " + total + " pages in the original file."); PdfDictionary pageDict; int currentRotation; for (int p = 1; p <= total; p++) { currentRotation = reader.getPageRotation(p); pageDict = reader.getPageN(p); pageDict.put(PdfName.ROTATE, new PdfNumber(currentRotation + rotation)); } PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); } catch (Exception e) { e.printStackTrace(); } }