pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Timo Rumland" <timo.ruml...@digitalys.de>
Subject Using PDFBox 2.0.0 with PrinterJob: MediaSizeName.ISO_A4 must be set to print in DIN A4
Date Wed, 27 Apr 2016 10:22:35 GMT

after migrating from PDFBox 1.8.2 to 2.0.0, I have to use
'MediaSizeName.ISO_A4' in combination with 'java.awt.print.PrinterJob' to
print a PDF document correctly in DIN A4.

Please, see the code below:


PDDocument pdDocument = PDDocument.load( new FileInputStream(
"pdf_din-a4.pdf" ) );

PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setJobName( "PDFBox is a great library" );
printerJob.setPrintService( PrintServiceLookup.lookupDefaultPrintService()
printerJob.setPrintable( new PDFPrintable( pdDocument ) );


 - In my case, the source PDF file (loaded by 'PDDocument.load(...)') is in
DIN A4 format.
 - Furthermore, the default printer on my dev system (Window 7 64 Bit) in

Using PDFBox 1.8.2, the output PDF file has the correct size of DIN A4.

Using PDFBox 2.0.0, the output PDF file is in DIN A4, but the contents of
the PDF is smaller, probably DIN A5 (so, the contents is scaled down and the
resulting PDF file has large white areas around the contents).

To get the same result as with PDFBox 1.8.2 using PDFBox 2.0.0, I have to
specify the media size like this:


// Code like above without 'printerJob.print();'

PrintRequestAttributeSet printRequestAttributeSet = new
HashPrintRequestAttributeSet( MediaSizeName.ISO_A4 );
printerJob.print( printRequestAttributeSet );


Now, while this works for me, there are several questions like:

 - Can this be considered a bug in 2.0.0, or maybe there was a bug in 1.8.2?
 - Should this be mentioned in the migration guide?
 - Or am I doing something wrong here?

Thanks a lot!

Best Regards,

To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message