阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria outlined in this document.
After opening a TIFF file, only the first page was processed; the program did not report any errors, yet it had already skipped the remaining content. For multi-frame formats, “successfully opening the file” and “completely processing the file” are two distinct matters. The entry point should first determine the number of pages, then decide whether to process them one by one, impose budgetary constraints, or generate a delivery checklist.
Copy the current image during each iteration frame
ImageSequence.Iterator
is suitable for iterating over multiple frames, but the frame objects may be tied to the underlying decoding state. If you intend to use each page independently later, you should either copy it during iteration or process it immediately. Do not repeatedly store references to the same mutable object and then expect to obtain pages that are mutually independent.
constructs two TIFF frames to verify that no pages are missing
from io import BytesIO
from PIL import Image, ImageSequence
first = Image.new("RGB", (12, 8), "white")
second = Image.new("RGB", (12, 8), "black")
stream = BytesIO()
first.save(stream, format="TIFF", save_all=True, append_images=[second])
stream.seek(0)
with Image.open(stream) as document:
assert document.n_frames == 2
pages = [frame.copy() for frame in ImageSequence.Iterator(document)]
assert len(pages) == 2
assert pages[0].getpixel((0, 0)) == (255, 255, 255)
assert pages[1].getpixel((0, 0)) == (0, 0, 0)
pages[0].putpixel((0, 0), (255, 0, 0))
assert pages[1].getpixel((0, 0)) == (0, 0, 0)
Here, keeping both pages entirely in memory is only suitable for this extremely small synthetic example. In real-world document scanning, each page should be processed individually or handled in controlled batches, with the results for each page recorded; it is not acceptable to copy all high-resolution frames and accumulate them indefinitely.
In addition to the page numbers, there are also page-by-page differences.
project
Why check page by page
recordable content
size
and the file page do not necessarily have the same size
width and height in pixels
pattern
Black-and-white and color pages may be mixed
Original Pattern and Transformation Strategy
direction
may differ across pages
page-wise orientation transformation
failure state
Damage to a certain page should not be ignored
page number, error category
partial success must be explicitly stated as
If nine out of ten pages have been processed, it is not sufficient to simply return a single file and mark everything as complete. The checklist should list the missing pages along with their reasons, allowing the user to decide whether to retransmit, process them individually, or accept a partial delivery. Page numbers should ideally retain their original numbering, rather than being renumbered due to skipped failed pages.
translation completeness starts from the input page count
uses
OmniDoc (Product Entry)
When processing multi-page scanned documents, the workflow can compare the input page list with the range of post-translation content. Identical page counts do not automatically confirm completeness, but missing pages or page numbers serve as highly valuable alerts. Integrity checks should be performed prior to linguistic polishing.
Reference:
Pillow ImageSequence
。
- 1 -
Updated 2026-10-08