Search code examples
javapdfitextpdf

PageSize of PDF always the same between landscape and portrait with itextpdf


I have a PDFReader which contains some page in landscape mode and other in portrait.

I need to distinct them to do some treatment... However, if I call the getOrientation or getPageSize, the value is always the same (595 for pagesize and 0 for orientation).

Why isn't the value different for a page in landscape ?

I've tryied to find other methods to retrieve page width / orientation but nothing worked.

Here is my code :

for(int i = 0; i < pdfreader.getNumberOfPages(); i++)
{
    document = PdfStamper.getOverContent(i).getPdfDocument();

    document.getPageSize().getWidth; //this will always be the same
}

Thanks !


Solution

  • Fix :

    use

    PdfStamper.getImportedPage(pdfReader, pagenumber).getBoundingBox().getWidth()
    

    instead of

    stamper.getOverContent(i).getPdfDocument().getPageSize().getWidth();