Table of Contents show
Cropping pages in a PDF document is useful if you want to remove margins, or focus on a specific section. Unlike image cropping, PDF cropping adjusts the visible area of the page without modifying its content.
Our Java PDF library JPedal contains a powerful PDF Manipulator which you can use to crop PDF files as well as performing other common edits.
You can download a trial copy from our website.
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
pdf.cropPage(new PageRanges("1-10"), 0.5f, 0.5f, ScaleMode.SCALE_BY_FACTOR);
pdf.cropPage(new PageRanges("1-10"), 595, 842, ScaleMode.SCALE_TO_DIMENSION);
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
You can either crop the page by a scale factor, or to a specific dimension.
See the Javadoc for more settings.
Resources
Learn more about the PDF Manipulator API.
We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!