title: ITextSharp crop PDF to remove white margins
body: <p>I am trying to remove white margins with iTextSharp. 
  I am trying get from this:
  <a href="https://i.stack.imgur.com/3DlkU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3DlkU.png" alt="enter image description here"></a></p>
  
  <p>to this:
  <a href="https://i.stack.imgur.com/QjhDt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QjhDt.png" alt="enter image description here"></a></p>
  
  <p>I used Textmargin fider but it only detects boundry for text.
  Heres my code</p>
  
  <pre><code>private Rectangle getOutputPageSize(PdfReader reader, int page)
  {
      PdfReaderContentParser parser = new PdfReaderContentParser(reader);
      PTextMarginFinder finder = parser.ProcessContent&lt;TextMarginFinder&gt;(page, new TextMarginFinder());
      double lijevo = finder.GetLlx();
      double desno = finder.GetUrx();
      double gore = finder.GetUry();
      double dole = finder.GetLly();
      return new Rectangle(finder.GetLlx(), finder.GetLly(), finder.GetUrx(), finder.GetUry());
  }
      private void button1_Click(object sender, EventArgs e)
      {
          string fileName = "e:\\test.pdf";
          if (File.Exists(fileName))
          {
              PdfReader pdfReader = new PdfReader(fileName);
              PdfStamper stamper = new PdfStamper(pdfReader, new System.IO.FileStream("E:\\gotovo\\test.pdf",FileMode.Append));
              for (int p = 1; p &lt;= pdfReader.NumberOfPages; p++)
              {
                  PdfDictionary page = pdfReader.GetPageN(1);
                  PdfArray cropBox;
                  PdfArray mediaBox;
                  cropBox = page.GetAsArray(PdfName.CROPBOX);
                  mediaBox = page.GetAsArray(PdfName.MEDIABOX);
                  //ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
                  //string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
                  Rectangle rect =getOutputPageSize(pdfReader, 1);
                  float[] flo = { rect.Left, rect.Bottom, rect.Right, rect.Top };
                  PdfArray pdfa = new PdfArray(flo);
                  //PdfArray pdfa = new PdfArray(mediaBox);
                  page.Put(PdfName.CROPBOX, pdfa); 
                  stamper.MarkUsed(page); 
                  //currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
                  //text.Append(currentText);
              }
              stamper.Close();
              pdfReader.Close();
          }
      }
  </code></pre>
  
  <p>My code does only this:
  <a href="https://i.stack.imgur.com/EqDu8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EqDu8.png" alt="enter image description here"></a>
  Is there any other way to get boundaries right?</p>