pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominic Eubel <dominic.eu...@plentymarkets.com>
Subject Problems with scaling and orientation for small pages (pdfbox 2.0.0)
Date Mon, 26 Oct 2015 10:54:05 GMT
Hey guys,
I hope, it's the right way for my problem :)

We need to print pdfs on very small pages. Like on 40mm x 26mm. (It's a 
Zebra thermal printer)
For testing, I want to print a A4-testpage on this little label.

If I try it with native dialog the a4 page is scaled correctly to 40x26. 
(equal if landscape or portrait with keeping aspect ratio).

Now, if I try to print with Java/pdfbox the page is not scaling correctly.
But if I try to print the a4 page with pdfbox on a a4-printer (landscape 
and portrait), it is scaling fine.

Some information for you:
- latest pdfbox 2.0.0
- MacOsx 10.10/10.11 and Windows
- Java 1.8

Here is source-code :

private static void printOne(PDDocument doc) throws IOException, 
PrinterException { PrinterJob job= PrinterJob.getPrinterJob(); PrintService[] printService=
PrinterJob.lookupPrintServices(); for(PrintService printer: printService) { System.out.println("Printer:
" + printer.getName()); if(printer.getName().equals("ZEBRA")) { try{ job.setPrintService(printer);
break; } catch (PrinterException pe) { pe.printStackTrace(); } } } Paper paper= new Paper();
paper.setSize(40 / (25.4 / 72), 26 / (25.4 / 72)); // It's working with a4 (210x297) 
double pWidth= paper.getWidth(); double pHeight= paper.getHeight(); paper.setImageableArea(0,
0, pWidth, pHeight); PageFormat pageFormat= job.defaultPage(); pageFormat.setPaper(paper);
pageFormat.setOrientation(PageFormat.PORTRAIT); // Or PageFormat.LANDSCAPE Book book= new
Book(); book.append(new PDFPrintable(doc, Scaling.SCALE_TO_FIT), pageFormat, doc.getNumberOfPages());
job.setPageable(book); job.print(); }

I hope, you can help me :)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message