PDF parsing

Why does the two-column PDF turn into a single column when extracted? First, preserve the coordinates; then discuss the reading order.

The left column is read halfway through when the next sentence abruptly transitions to the formula explanation in the right column. Such issues do not necessari

阅读文本 / 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-world 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 left column is read halfway through when the next sentence abruptly transitions to the formula explanation in the right column. Such issues do not necessarily stem from recognition: the words may all be correct, but their order is wrong. For typical two-column papers, one should generally finish reading an entire section of the left column before moving on to the right column; interleaving the two columns line by line at the same height actually disrupts the paragraph structure. Before addressing the ordering issue, first preserve the text’s coordinates and source page. Do not rush to compress the entire page into a single long string: once regional information is lost, subsequent translations will receive context that has already been misaligned, and even switching to a different translation model may not be able to remedy the situation. sort=True is worth trying, but it is not a layout interpreter PyMuPDF offers various extraction formats, including text, words, and blocks. sort The specific handling varies depending on the output type and version; it cannot be universally described as a single, fixed typesetting algorithm, nor can one use it to guarantee the restoration of the reading order for all documents. For rule-based pages, one can first compare the results of sorting with and without sorting enabled. For pages containing column-spanning headers, side notes, or footnotes, it is necessary to further examine the spatial relationships among these elements. PDFs may also contain structural tags, but this does not mean that the currently employed extraction interface will automatically produce the semantic paragraph tree you require. This paper does not implement general layout recognition; instead, it demonstrates only “how to sort after existing region rules have been applied,” thereby clearly delineating the scope of its capabilities. illustrates the problem using five synthetic text blocks The page width is set to 600 points, with column dividers at 300; the area within 80 points from the top constitutes the multi-column header section, below which lies the main text area. The input is deliberately scrambled: the second paragraph of the right column precedes the first paragraph of the left column. Each tuple contains the four coordinates of a rectangle along with its text. Here is our simplified structure as defined, without claiming to represent get_text("blocks") complete return value. The expected result should be: the title, the first paragraph of the left column, the second paragraph of the left column, the first paragraph of the right column, and the second paragraph of the right column. A block of text that spans the column boundary must be placed in the exception list, rather than being silently discarded or forcibly squeezed into the left column. A small example that can run completely uses only the Python standard library. When actually interfacing with PyMuPDF, you can extract the first five fields from the block results and first exclude non-text blocks. Here, no external files are opened, OCR is not required, and column boundaries are not inferred automatically. def order_known_layout(blocks, split_x=300, title_bottom=80): groups = {"title": [], "left": [], "right": []} rejected = [] for block in blocks: x0, y0, x1, y1, text = block if x1 <= x0 or y1 <= y0: rejected.append(block) continue if y1 <= title_bottom: region = "title" elif y0 < title_bottom: rejected.append(block) continue elif x1 <= split_x: region = "left" elif x0 >= split_x: region = "right" else: rejected.append(block) continue groups[region].append(block) ordered = [] for region in ("title", "left", "right"): ordered.extend(sorted(groups[region], key=lambda b: (b[1], b[0]))) return [b[4] for b in ordered], rejected sample = [(330, 160, 550, 190, "R2"), (40, 100, 270, 130, "L1"), (40, 20, 550, 50, "TITLE"), (330, 100, 550, 130, "R1"), (40, 160, 270, 190, "L2")] ordered, rejected = order_known_layout(sample) assert ordered == ["TITLE", "L1", "L2", "R1", "R2"] assert rejected == [] wide = (40, 220, 550, 250, "FULL WIDTH BODY") assert order_known_layout(sample + [wide])[1] == [wide] assert order_known_layout([]) == ([], []) print("known-layout examples: 3 assertions passed") 80 and 300 both originate from the settings of this composite page; they are not the empirical thresholds that should be replicated across all PDFs. When encountering a change in the left- and right-column widths on the next page, retaining the parameters from the previous page may result in “normal operation but incorrect content.” Region rules should follow the page; at a minimum, record the rule version along with the original page dimensions. Acceptance testing should not focus solely on whether errors are reported check item What should be seen in this set of examples? What to do when it doesn’t comply region order After the title, first complete the left column, then complete the right column checks the partitioning rules, without relying on string-swapping patch fixes for Content conservation accepts the number of blocks plus the number of rejected blocks equals the number of input blocks blocks delivery; check whether there are silent packet losses Cross-bar main text appears in the rejection list adds a cross-bar section, or is subject to manual determination by rotation and cropping input block and partition use the same coordinate system first standardizes the coordinates, then performs the containment check header, footer is categorized separately according to business rules does not delete all bottom text without exception The original paper may also insert a figure spanning multiple columns in the middle, with a two-column layout restarting below it. In such cases, the page must first be divided into upper and lower sections, then sorted separately; the single three-part partition used in this paper is insufficient. Vertical Chinese text, right-to-left writing, and complex marginal notes should likewise not adopt this reading direction. How do I integrate into OmniDoc’s translation workflow? The value of a custom script lies in clearly articulating your acceptance criteria; the value of off-the-shelf translation tools is in reducing the operational steps between the source file and the translated manuscript. The two are not mutually exclusive. OmniDoc (Product Entry) provides the document translation entry point, and the official website also introduces OCR, terminology lists, and bilingual comparison features. You can take a de-identified paper that you’re authorized to upload and use the same checklist to review the translation. focuses on whether the first sentence following the cross‑bar title is correctly matched, whether figure captions have been integrated into the main text, and whether footnote citations remain consistent. This assessment evaluates the delivered output, not an inference about OmniDoc’s internal algorithms. If the results do not meet the requirements, retain the original page and the erroneous sections; first determine whether the issue lies in recognition, sorting, or translation, then decide how to proceed with corrections. Start with one page, rather than revising the entire book at once. First, select a representative two-column page, manually annotate how it should be read, and then run the rule. Retain both successful and failed samples, and after adjusting the rule, re-run it on the entire set. A rule is only worth deploying in batch processing if it preserves existing correct results while also addressing new issues. interface and extraction form reference: PyMuPDF Official Text Extraction Guide . The example tests a known region ordering and does not imply that the layout analysis performance has been validated for any arbitrary PDF. - 1 -
Updated 2026-10-08