Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed May 30, 2018 7:48 pm

How can I determine if the pdf is a native pdf or a scanned document?

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Thu May 31, 2018 3:10 am

Hi,

Thanks for your inquiry.
I am afraid that there is no direct way to determine if a PDF is scanned document. As far as I know, the scanned document only has images without any text. Maybe you could use the two conditions to achieve what you want. Sample code for your reference:
Code: Select all
       private static bool ScannedPDF = false;
        public static bool scannedPDF()
        {
            StringBuilder content = new StringBuilder();
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile(FilePath + "Scan that works fine.pdf");
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                PdfPageBase page = doc.Pages[i];
                Image[] images = page.ExtractImages();
                content.Append(page.ExtractText());
                if (images != null && content.ToString() == string.Empty)
                {
                    ScannedPDF = true;
                }
                else if (content.ToString() != string.Empty)
                {
                    ScannedPDF = false;
                    break;
                }                   
            }
            return ScannedPDF;           
        }

Any question, just feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu May 31, 2018 6:13 pm

Thank you for the example code Betsy.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Jun 01, 2018 1:43 am

Hi,

If there is any question while using our product, please do not hesitate to contact us.
Have a nice day.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF