3

I have a problem printing a landscape document (doc.width > doc.height). I have no problem with portrait. I'm using the PDFBox 1.8.2 library. It prints the document in portrait even if I set landscape mode manually like in this blog. There are several closed JIRA bugs about this problem in the PDFBox project. How do I print landscape?

Note: I've added extra PDF library tags to flag users of those libraries to see if this problem exists in those libraries.

Code from the blog post:

Version : PdfBox-1.7.1 

PDDocument doc = PDDocument.load(psStream,true);

if (printService != null) {             

    PrinterJob pj =  PrinterJob.getPrinterJob();
    pj.defaultPage();
    pj.setCopies(Integer.parseInt(finalnumberOfCopies));
    pj.setPrintService(printService);
    pj.setPageable(new MyPDPageable(doc,pj));

    // don't use doc.silentPrint(pj) but pj.print() ...
    pj.print();
}
JoshDM
  • 4,939
  • 7
  • 43
  • 72
Zaur Guliyev
  • 4,254
  • 7
  • 28
  • 44

1 Answers1

0

This example at grepcode.com worked for me. To summarize, it first rotates a portrait page 90 degrees to get the landscape orientation, and then uses the concatenate2CTM method to similarly rotate your contentStream.

  • Welcome to Stack Overflow! While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. See [How do I write a good answer](http://stackoverflow.com/help/how-to-answer). – ByteHamster May 06 '15 at 14:31