Search code examples
pdfpdf-generationpdfbox

Create PDPage with right format using PDFBox


I'm trying to write a simple method that creates a new PDDocument and adds PDPage with the right page format as supplied by user inputs.

Input from User can be one of the following:

"A4-Portrait"
"A4-Landscape"
"A3-Portrait"
"A3-Landscape"

Expected output: If input is "A3-Landscape" , return PDPage with this format.

while I can see ways to create PDPage in A3 format using

PDPage page = new PDPage(PDRectangle.A3);

Can you help how efficiently and easily can I choose the right format and its orienatation dynamically?


Solution

  • You can do it like this:

    PDRectangle A4L = new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth());