Method DetectBlankPages
DetectBlankPages(Attachment, byte, CancellationToken)
Detects visually blank pages in a PDF attachment - the classic separator sheets slipped between documents in a batch scan.
public static List<int> DetectBlankPages(Attachment source, byte tolerance = 10, CancellationToken cancellationToken = default)
Parameters
sourceAttachmentThe source PDF attachment.
tolerancebytePer-channel noise tolerance (0-255) for scanned pages: a page counts as blank when every pixel matches the first one within this tolerance AND the page is light (a uniformly dark page is content, not a blank). The default 10 absorbs typical scanner noise; use 0 for born-digital PDFs.
cancellationTokenCancellationTokenCancels the operation between pages.
Returns
- List<int>
The 0-based indexes of the blank pages, in ascending order - consistent with ExtractPages(Attachment, int[], CancellationToken).
Examples
var source = new Attachment("batch_scan.pdf");
List<int> blanks = PdfSplitter.DetectBlankPages(source, tolerance: 10);
Remarks
A page with no content objects at all (no text, image, path, or shading) is blank without rendering. Pages with content are rendered at a reduced resolution and tested for uniformity and lightness, so a page carrying a full-bleed white rectangle still reads as blank while a solid dark page never does. Annotations are not considered.
Combine with Split(Attachment, IEnumerable<string>, CancellationToken) to split a batch scan on its separator sheets: the runs of non-blank pages between the returned indexes are the documents.