0

I am currently trying to generate PDF file in landscape mode using Apache PDFBox version 2.0.17.

In Portrait mode, PDF got generated properly.
In landscape mode, the data in PDF is also rotating to 90 degree.
Is it possible to create PDF in landscape mode using Apache PDFBox?

To create landscape PDF I am using below code,

PDPage page = new PDPage();

page.setMediaBox(PDRectangle.A4);

page.setRotation(90);
vimuth
  • 5,064
  • 33
  • 79
  • 116
Sathish
  • 1
  • 1
  • Does this answer your question? [Create PDPage with right format using PDFBox](https://stackoverflow.com/questions/72727885/create-pdpage-with-right-format-using-pdfbox) – Tilman Hausherr Jul 14 '22 at 03:14
  • Thanks for your reply, above solution is not helping and I need to create landscape PDF and fill in the data in the same format.. – Sathish Jul 14 '22 at 05:55
  • How is it "not helping"? There's also an example `CreateLandscapePDF.java` in the examples subproject of the source code download. Please include shortest possible fully working code and explain what you expected and what happened instead. – Tilman Hausherr Jul 14 '22 at 07:43
  • Using CreateLandscapePDF.java I could get the PDPageContentStream to be in same format as Landscape Format. But my requirement has tables and complex structures like inner tables. How can we have transform work in PDFBox. I find it difficult to understand the co-ordinates of the PDF. Help me if there is any documentation for getting hold of this scenario. – Sathish Jul 14 '22 at 10:31
  • That is a different question and also unclear. You need some knowledge about affine transforms (may have been done in school math, long ago) to understand how to do a rotation. The best would be that you separate whatever you're doing into separate problems. SO only helps against specific road blocks. Btw with the linked solution you wouldn't have to rotate at all. Also important: in PDF the (0,0) coordinate is at the bottom left. – Tilman Hausherr Jul 14 '22 at 11:08

0 Answers0