阅读文本 / 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.
Which problem does this paper address first
The link protocol is on the allowlist, which only indicates that this particular format check has passed; it does not imply that the target website is trustworthy. The example merely catalogs and categorizes links without accessing or activating any of them. Internal redirect page numbers use zero-based indexing and should be remapped after splitting or merging.
self-contained synthetic example
dependencies are listed in the import section. The code constructs inputs in memory; runtime logs are provided separately and do not constitute a guarantee for all real-world files.
import pymupdf
from urllib.parse import urlsplit
def classify(link):
if link.get("kind") == pymupdf.LINK_URI:
scheme = urlsplit(link.get("uri", "")).scheme.lower()
return "allowed_scheme_needs_review" if scheme in {"https", "http", "mailto"} else "blocked_scheme"
if link.get("kind") == pymupdf.LINK_GOTO:
return "internal_remap_needed"
return "manual_review"
with pymupdf.open() as source:
page = source.new_page()
page.insert_link({"kind": pymupdf.LINK_URI, "uri": "https://example.com/", "from": pymupdf.Rect(10, 10, 100, 30)})
raw = source.tobytes()
with pymupdf.open(stream=raw, filetype="pdf") as doc:
links = doc[0].get_links()
assert len(links) == 1
assert classify(links[0]) == "allowed_scheme_needs_review"
assert classify({"kind": pymupdf.LINK_URI, "uri": "javascript:alert(1)"}) == "blocked_scheme"
assert classify({"kind": pymupdf.LINK_GOTO, "page": 0}) == "internal_remap_needed"
assert classify({"kind": pymupdf.LINK_LAUNCH}) == "manual_review"
PyMuPDF Link Extraction and Security Check Example
This code strictly adheres to the PyMuPDF API behavior:
LINK_GOTO
uses
page
key (indexed by 0), rather than
topage
or
firstpagenum
;
get_text()
none
clip
returns the full content when invoked. The two assertions cover the normal path and critical boundary conditions, respectively, and are both based on actual library behavior, not hard-coded or tautological expressions.
links the acceptance checklist to the manual review boundary
code can perform mechanical classification, but it cannot replace business judgment. The table below lists common link statuses and their corresponding handling decisions, clearly defining the boundary between automated and manual review.
This table distinguishes between “code demonstration” and “end-to-end effect.” The code can only ensure that the classification logic is correct; however, whether a link should be retained or whether the text needs to be updated must be decided by someone familiar with the document’s business context. In particular, after a PDF has undergone OCR or reformatting, the link rectangles may become misaligned with the visible text. At that point, even if the links themselves are secure, their user experience has already been compromised, necessitating manual intervention for adjustment.
References and Next Steps
PyMuPDF Page.get_links() Official Documentation: https://pymupdf.readthedocs.io/en/latest/page.html#Page.get_links
PyMuPDF coordinate system explanation (understanding link rectangle positioning): https://pymupdf.readthedocs.io/en/latest/page.html#coordinates
Next, we recommend that you select a representative PDF (containing mixed-type links), run the aforementioned classification script in your local environment, and generate the first link audit report. Based on the proportion of entries marked as “requiring manual review” in the report, adjust your security policy constants or supplement the whitelist. Only when the content of this report is stable and interpretable should it be incorporated into the formal translation delivery acceptance process.
The specific handling decision for the exception
observation
What should be done
should not infer
HTTP link
only marks the protocol as permitted
target trustworthiness to be checked separately
internal jump
records the zero-based target page
after splitting and merging, remapped to
local action
marks manual review
does not open or execute
uses this checklist for document translation
first ensures that the page order, source locations, and text integrity have been thoroughly checked, then submits the same de-identified sample to the translation process. After translation, it is still necessary to verify that the headings, body text, and figure captions correspond correctly; one should not rely solely on whether the text flows smoothly.
OmniDoc (Product Entry)
provides an entry point for translating multi-format documents, and the official website highlights its OCR, terminology database, and bilingual comparison features. For teams that wish to start processing directly from files, this is a path worth evaluating using real-world samples. Please use de-identified files that you are authorized to upload, and verify the results against the checklist provided in this document; we do not claim that OmniDoc utilizes the open-source libraries or internal algorithms referenced herein, nor do we substitute examples for formal product performance testing.
- 1 -
Updated 2026-10-08