you can use iText to move, scale or crop pdf pages
you need to define a PdfReader for the source file and a document for your target file, then you iterate over the pages, if Reader, create a new page in the document and add the original page as a template to the new page (moving, scaling, etc., wherever you are wanted to)
PdfReader reader = new PdfReader( input ); int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.getHeight(); float height = psize.getWidth(); Document document = new Document(new Rectangle(height, width)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( output )); document.open(); PdfContentByte cb = writer.getDirectContent(); int i = 0; while (i < n) { i++; document.newPage(); PdfImportedPage page = writer.getImportedPage(reader, i); cb.addTemplate(page, factor, 0, 0, factor, left, down); } document.close();
Nikolaus Gradwohl
source share