title: itext get content size
body: <p>I just spent a few hours scouring the web. It seems others also have this issue, but I couldn't find an answer.</p>
  
  <p>I have a whole bunch of PDF files that I need to get their measurements, namely their height and witdh of the pages content.</p>
  
  <p>In Adobe Illustrator, when you import a PDF you have the option of triming to the "bounding box". That's exactly what I need.</p>
  
  <p>I tried many approaches, here's the hodgepodge:</p>
  
  <pre><code>Dim pdfStream = IO.File.OpenRead(FilePath)
  Dim img = PdfImages(pdfStream)
  Dim pdfReader = New PdfReader(pdfStream)
  Dim pdfDictionary = pdfReader.GetPageN(1)
  Dim mediaBox = pdfDictionary.GetAsArray(PdfName.MEDIABOX)
  Dim b = pdfReader.GetPageSize(pdfDictionary)
  Dim ms = New MemoryStream
  Dim document = New Document(pdfReader.GetPageSizeWithRotation(1))
  Dim writer = PdfWriter.GetInstance(document, ms)
  document.Open()
  document.SetPageSize(pdfReader.GetPageSize(1))
  document.NewPage()
  Dim cb = writer.DirectContent
  cb.Clip()
  Dim pageImport = writer.GetImportedPage(pdfReader, 1)
  pdfReader.Close()
  pdfStream.Close()
  </code></pre>
  
  <p>All I manage to get is the page size, which is useless. I tried this on a whole bunch of PDFs, so it's not like one corrupt file or something.</p>