开发者

How to remove blank pages from PDF using PDFSHarp?

How will i be able to remove a blank page from a PDF file? I have a sample PDF file where the 1st page contains a few strings and a 2nd page with absolutely NOTHING in it. I tried to loop into the pdf pages and get the element count PER page but the funny thing is that i get the same number between the 2 pages =| How did that happen开发者_JS百科 if the 1st page has a few strings and the 2nd page was absolutely blank???

This is my code

Dim inputDOcument As PdfDocument = PdfReader.Open("") Dim elemountCount As Integer = 0 Dim elemountCount2 As Integer = 0 Dim pdfPageCount As Integer = inputDOcument.PageCount

For x As Integer = 0 To pdfPageCount - 1 elemountCount = inputDOcument.Pages(x).Contents.Elements.Count elemountCount2 = inputDOcument.Pages(x).Elements.Count Next


Try to check length of each element:

public bool HasContent(PdfPage page)
{
    for(var i = 0; i < page.Contents.Elements.Count; i++)
    {
        if (page.Contents.Elements.GetDictionary(i).Stream.Length > 76)
        {
            return true;
        }
    }
    return false;
}


You can try the PDFsharp Document Explorer that comes with PDFsharp to see what the PDF file really contains. Or load and save the file with a PDFsharp DEBUG build, this will give you a "verbose" file. Viewing that with Notepad could help to understand what the file contains.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜