

PdfUnitConvertor unitCvtr = new PdfUnitConvertor() You can try the following code to set margins.Ĭode: Select all PdfDocument doc = new PdfDocument() Look under Pages -> Advanced -> Resize Pages.To set the margin, you have to create a new pdf and clone the original content.īut pay attention that you have to change the pagesize of the new pdf, which means make the new pdf pagesize different from the original one. You can try the functionality in our end-user application PDF Studio, which makes it simple to visualize the different resize properties available. PdfDoc.saveDocument("C:/qoppa/test/out.pdf") ĭownload the full Resize PDF Pages Java Sample. Set the crop box to the same size as the media box Scale the page contents to fit the new page size tMediaBox(new Rectangle2D.Double(0, 0, width, height)) Get the page size A3 (297mm x 420mm) in points ResizePageOptions options = new ResizePageOptions() PDFDocument pdfDoc = new PDFDocument("C:/qoppa/test/in.pdf", null) resizePage (options ) // Save the output document setFitToMedia ( true ) // Resize the page setCenter ( true ) // Set the crop box to the same size as the media box setAutoScale ( true ) // Center the page contents on the page Double ( 0, 0, width, height ) ) // Scale the page contents to fit the new page size

ResizePageOptions options = new ResizePageOptions ( ) // Get the page size A3 (297mm x 420mm) in points double width = 297 / 25.4 * 72.0 double height = 420 / 25.4 * 72.0 // Set the new Media Box getPage ( 0 ) // Create ResizePageOptions object PDFDocument pdfDoc = new PDFDocument ( "C:/qoppa/test/in.pdf", null ) // Get the first page of the PDF The page content is re-scaled and centered to fit the new format. Media Box and Crop Box will be resized to A3. Here is a Java sample program that will open a PDF and resize its pages to A3 format.

If center or auto scale is on, then this value is not used. XOffset, YOffset – x and y offset of the page contents.Auto Scale – option to scale the page contents to fit inside the new media box (off by default).Center – option to center the page contents in the new media box (off by default).Media Box – new media box for the PDF Page.Starting with v2017R1, Qoppa Java PDF library jPDFProcess offers an API to easily resize or change page sizes in a PDF document.
