阅读文本 / 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.
“The same piece of code runs on my computer” is not a reproduction report. PDF rendering and document conversion are also affected by library versions, system fonts, OCR language packs, and external components. Only by collecting all this information can one determine whether the differences stem from the input, the code, or the environment.
separately records Python packages and system resources
importlib.metadata
can read the installed distribution package version, but it cannot access all fonts, system dynamic libraries, or external OCR data files. Do not treat a
pip freeze
The list is called the complete environment. The package’s distribution name and import name may also differ; for example, importing
PIL
The corresponding distribution package is
Pillow
。
A reporter that does not crash due to packet loss
import json
import platform
from importlib import metadata
def package_version(name):
try:
return metadata.version(name)
except metadata.PackageNotFoundError:
return "not-installed"
def report(names):
return {"python": platform.python_version(),
"system": platform.system(),
"packages": {name: package_version(name) for name in names},
"fonts_manifest": "not-collected",
"ocr_language_data": "not-collected"}
data = report(["PyMuPDF", "Pillow", "omnidoc-synthetic-missing-package"])
assert data["packages"]["omnidoc-synthetic-missing-package"] == "not-installed"
assert data["python"]
assert data["fonts_manifest"] == "not-collected"
assert json.loads(json.dumps(data)) == data
code only reads the current environment, does not install dependencies, and does not connect to the internet. Uncollected items in the results should remain explicitly marked and must not be automatically filled with “default font” or “latest version.” The report may optionally link to container image digests, lock files, and input file digests, but it should not export authentication configurations or all environment variables.
When comparing, first look for the most discriminative information.
difference
Common impact direction
subsequent verification
font missing
alternative font and typographic changes
compares the font list with the rendering sample
OCR language pack differs
identification path change
Re-testing using the same language data
Different versions of the PDF library
interface or parsing behavior change
Check the version documentation and run the minimum sample
input summary differs
It is not the same file at all.
first performs unified input, then discusses the environment
A identical environment does not guarantee that all outputs are identical byte-for-byte
timestamps, random IDs, and compressed metadata can also cause changes in the product hash. It is necessary to distinguish between “byte-level reproducibility” and “content and layout meeting the same acceptance criteria.” First determine which type of assurance is required, then select an appropriate comparison method to avoid using the wrong metric.
makes it easier to communicate about document translation issues
when the local preprocessing result matches
OmniDoc (Product Entry)
workflow discrepancies can be accompanied by desensitized samples, processing stages, and environment reports. Such feedback is easier to pinpoint than a simple remark like “the formatting is messed up,” and it also helps determine whether dependencies need to be updated, fonts need to be supplemented, or input preparation needs to be adjusted.
Reference:
Python importlib.metadata
。
- 1 -
Updated 2026-10-08