Datagrunt 4.6.7: Table Positions and No Duplicate Cell Text on Cropped and Rotated PDFs
Datagrunt 4.6.7 fixes PDF tables on cropped, offset-origin and rotated pages, for both the pdfium and pymupdf engines.
What Was Wrong
When PDFReader finds a table, it drops body text that lies inside the table so the cells appear only once, inside the table element. Table detection reported positions in a different coordinate frame from the page text whenever a page was cropped, had a MediaBox that does not start at the origin, or was rotated. On those pages:
- the table element’s
positionwas shifted, and - table cell text was emitted a second time as
body_textorheaderelements.
Uncropped, unrotated pages — most PDFs — were not affected, and their output does not change.
What Changed
Table positions are now converted into the same frame each engine uses for its text, on every page rotation and crop. In the regression tests, table positions match the rendered page, no cell text is duplicated, and body text outside the table is still emitted, for both engines.
from datagrunt import PDFReader
page = PDFReader("cropped_financial_report.pdf").to_dicts()["document"]["pages"][0]
for element in page["elements"]:
position = element["position"]
if element["type"] == "table":
print("table", position, element["metadata"]["rows"], "x", element["metadata"]["columns"])
else:
print(element["type"], str(element["content"])[:30])Known Limitations
- Cell text on rotated pages. On pages rotated 90° or 270° the cell grid is transposed, and on pages rotated 180° or 270° the characters inside a cell are reversed (
PartreadstraP). Table placement is correct; the cell content is not yet. A fix is tracked in #387. engine="pymupdf"still reports coordinates in the unrotated page frame on rotated pages; its tables now follow that same frame.
Note for Code That Uses datagrunt.core Directly
PdfPlumberTableExtractor.extract() now returns display-frame coordinates on cropped, offset-origin and rotated pages (unchanged elsewhere).
Upgrading
uv pip install --upgrade datagrunt