1

This is continuation of the previous question. (Removing Empty Pages in a PDF document using C#) Many thanks for all the help.

Im trying to remove random empty pages from a PDF document which has more than 500 pages. With the help of previous question answers, I thought of iterate through the whole PDF page by page, scan the content and if content is empty remove the empty page.

Now, Im trying to identify the emptiness of the page like shown below. But, below code does not work as pdfPage.ClientRectangle.IsEmpty returns false for empty pages as well.

for (int i = 0; i < completePdf.Pages.Count; i++)
{
    PdfPage pdfPage = completePdf.Pages[i];
    bool isEmpty = false;
    if (completePdf.Pages[i] != null)
    {
        isEmpty = pdfPage.ClientRectangle.IsEmpty; // this gives false to empty/blank page
    }
    // page removal logic
    if (isEmpty)
    {
        // RemoveAt method usage - http://selectpdf.com/docs/M_SelectPdf_PdfDocument_RemovePageAt.htm

    }
}

Any help will be much appreciated and thanks in advance.

Liam
  • 27,717
  • 28
  • 128
  • 190
BUDDHIKA
  • 306
  • 2
  • 8
  • 23
  • 1
    Do you have a question? Where are you stuck? You seem to know what to do ... – Fildor Aug 31 '17 at 09:38
  • Above code does not identify the blank pages as pdfPage.ClientRectangle.IsEmpty returns false for empty pages as well. Just wanted to get some help in finding blank pages. Thanks. – BUDDHIKA Aug 31 '17 at 09:43
  • There is a difference between an empty page and that that contains white space white space is not empty. I don't know this library but it sounds to me whatever you turning into a PDF is where the problem lies. It's probably too wide for the page format your setting or contains rogue whitspace characters. I'd focus your attention here rather than trying to get the library to clean this up for you. – Liam Aug 31 '17 at 09:50
  • Ah, that makes it clearer. I second Liam: Read the docs of the lib on what exactly is considered "empty". – Fildor Aug 31 '17 at 10:06

0 Answers0