Detect orientation of PDF with iTextSharp package and a code snippet

  1. Download iTextSharp from package manager
    image

  2. Import iTextSharp.text under namespaces
    image

  3. Now you can use invoke code with this snippet to determine whether a page in pdf is portrait or landscape

Dim Reader As New iTextSharp.text.pdf.PdfReader(pdfPath)
Dim Rect = Reader.GetPageSizeWithRotation(pageNum) 'pageNum starts at 1
out_isPortrait = Rect.Height >= Rect.Width
'if out_isPortrait  = True, orientation=Portrait, else orientation=Landscape

Reusable module attached here (make sure iTextSharp package is installed first)
GetOrientationOfPDF.xaml (10.5 KB)

1 Like