package jPDFPrintSamples; import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.PrinterJob; import com.qoppa.pdf.PrintSettings; import com.qoppa.pdfPrint.PDFPrint; public class OverrideMargins { public static void main (String [] args) { try { // Load the document PDFPrint pdf = new PDFPrint ("input.pdf", null); // Set print settings PrintSettings ps = new PrintSettings (); ps.setForceUserPageFormat(true); pdf.setPrintSettings(ps); // Create our own PageFormat using Letter sized paper with 2 inch margins Paper p = new Paper(); p.setSize(8.5 * 72, 11 * 72); p.setImageableArea(2 * 72, 2 * 72, 4.5 * 72, 7 * 72); PageFormat pf = new PageFormat (); pf.setPaper(p); // Create our own printer job PrinterJob pJob = PrinterJob.getPrinterJob(); pJob.setPrintable (pdf, pf); // Print pJob.print(); } catch (Throwable t) { t.printStackTrace(); } } }