Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Scanned Document Detection

ComPDFKit supports detecting whether a PDF document is a scanned document (image document). Scanned documents are typically generated by scanners, where page content is stored as images rather than selectable text. ComPDFKit provides two levels of scanned document detection: document level and page level.

Detect Scanned Document (Document Level)

Use the CPDFDocument.isImageDoc() method to determine whether the entire PDF document is a scanned document. Here is an example:

java
CPDFDocument document = new CPDFDocument();
document.open("test.pdf");
bool isScannedDocument = document.isImageDoc(); // Returns true if it is a scanned document
if (isScannedDocument)
{
    // This document is a scanned document, may need OCR processing to extract text
}

Detect Scanned Page (Page Level)

Use the CPDFPage.isImagePage() method to determine whether a single page is a scanned page (image page). This method is suitable for mixed documents where some pages are scanned images and some pages are regular text. Here is an example:

java
CPDFDocument document = new CPDFDocument();
document.open("test.pdf");
for (int i = 0; i < document.PageCount; i++)
{
    CPDFPage page = document.PageAtIndex(i);
    bool isImagePage = page.isImagePage(); // Returns true if the page is a scanned/image page
    if (isImagePage)
    {
        // This page is a scanned page, may need OCR processing to extract text
        System.out.println("" + i + "页是扫描页");
    }
}

Comparison of Two Detection Methods

MethodLevelUse Case
CPDFDocument.IsImageDoc()Document levelDetermine if the entire document is a scanned document, suitable for quick document type filtering
CPDFPage.IsImagePage()Page levelDetermine if a single page is a scanned page, suitable for processing mixed documents or page-by-page analysis

What is a Scanned Document?

A scanned document is a PDF file created by converting a paper document to an electronic document using a scanner or camera. The characteristic of such documents is that page content is stored as images, making it impossible to directly select or search text within. Identifying scanned documents helps determine whether OCR (Optical Character Recognition) processing is needed.