TECHNOLOGY

Multi-page TIFF documents: verify page coverage beyond the first decoded image

In this article
THE QUICK TAKE

Retain document identity, complete page membership and annotation coverage per page.

A decoded first image is not a complete document

An OCR preparation job opens each TIFF successfully and emits a single image per file. For a document collection whose primary TIFF frames represent pages, this can silently omit the rest of a scanned report. Establish that source convention before equating frames with pages: TIFF is a container format, not a universal document-page schema. Retain the source document identity and expected primary-frame membership independently of the number of files the intake job accepted.

Enumerate the loader’s frame space explicitly

The Pillow TIFF documentation describes n_frames and zero-based frame numbers, with seek selecting a frame and tell reporting the current position. Read dimensions and relevant page metadata after selecting the intended frame. A top-level object opened successfully does not establish that every frame was decoded. Record which frames were visited and which supplied usable page content rather than deriving page coverage from a single initial image size.

Distinguish the end from an incomplete traversal

Seeking beyond the final frame raises EOFError under the documented loader contract. When using that boundary to finish iteration, distinguish the expected end position from failure while processing an expected page. Do not turn arbitrary decoder exceptions into successful completion. The ImageSequence reference offers an iterator over frames; it also documents indexed access raising IndexError for a nonexistent frame. Preserve these API distinctions in the wrapper instead of catching every exception as though it meant an ordinary end.

Keep serialization inside the page-coverage boundary

A preparation stage can enumerate every page and then save only a single frame. The TIFF guide documents the multi-frame saving path through save_all or nonempty append_images. Select the intended path explicitly and reopen the produced artifact to inspect its membership. A correct in-memory count is insufficient when later serialization drops pages. If materializing separate page images, preserve the mapping to source frame identity so sorting output filenames cannot silently reorder the document or attach OCR labels to another page.

Exercise a document-specific round trip

Construct a harmless multi-page fixture with distinct page markers, different dimensions and known page-level annotations. Enumerate through the actual production reader, interrupt traversal, reopen and repeat the declared continuation procedure. Then serialize using the intended output mode and reload it. Acceptance requires every expected page marker and annotation association to survive, with no duplicated or missing member. Include a deliberately first-frame-only export that the checker rejects. No TIFF decoding, OCR job or serialization experiment was executed here.

Preserve partial results without claiming full coverage

EXIF coordinate handling addresses geometry inside an image. Document provenance connects extracted evidence to its source. This article instead establishes membership of the document’s expected pages. If an expected frame fails, retain its identity and unresolved status alongside any usable pages; do not relabel the partial document complete. Even full frame coverage does not prove correct OCR, within-page reading order or interpretation of every TIFF substructure. State those boundaries with the accepted output.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles