Hi,

> PageFormat pf = job.defaultPage();

PrinterJob#defaultPage() creates a new page, it can’t be used to modify the 
default, see:
http://docs.oracle.com/javase/6/docs/api/java/awt/print/PrinterJob.html#defaultPage()
 
<http://docs.oracle.com/javase/6/docs/api/java/awt/print/PrinterJob.html#defaultPage()>

The PageFormat which will be used for the job is controlled by the Pageable 
instance,
i.e, this line:

> job.setPageable(printer.getPageable());


That’s a PDFPageable instance, which PDFPrinter creates for you. To specify a 
custom
Paper, you need to pass it to PDFPrinter , we provide a constructor which you 
can use:

PDFPrinter(PDDocument, Scaling, Orientation, Paper)

Call this with Scaling.SHRINK_TO_FIT and Orientation.AUTO.

-- John

> On 26 Jan 2015, at 13:31, Josh Nankin <[email protected]> wrote:
> 
> When I print a PDF using the below code, the PDF appears smaller in the
> result than the original file.  How do I solve this?
> 
> Input: http://joshnankin.com/input.pdf
> What prints: http://joshnankin.com/whatPrints.pdf
> 
> 
> Code:
> 
>        PDFPrinter printer = new PDFPrinter(PDDocument.load(new
> File("input.pdf")));
> 
>        PrinterJob job = PrinterJob.getPrinterJob();
>        PageFormat pf = job.defaultPage();
>        Paper paper = new Paper();
>        paper.setSize(612, 792);
>        double margin = 0;
>        paper.setImageableArea(margin, margin, paper.getWidth() - margin,
> paper.getHeight() - margin);
> 
>        pf.setPaper(paper);
>        job.setPageable(printer.getPageable());
>        job.setJobName("test");
>        job.printDialog();
>        try {
>            job.print();
>        } catch (PrinterException e) {
>            System.out.println(e);
>        }

Reply via email to