Turning a PDF Measurement Report into a Reviewable Summary

By View as Markdown

Graphic showing some documents concerned wth measurements & metrics

A measurement report is only useful if someone can review it quickly. With PyMuPDF & about 100 lines of Python read every table in a PDF report and append a final page that answers the reviewer's first questions: how many readings, the range, the mean, and what's wrong with the data.

The problem is familiar to anyone in quality assurance. A supplier sends a report with 120 readings spread across five pages. The reviewer has a spec to check, and somewhere in those tables are a blank cell and a reading in the wrong unit. Scanning by eye is slow, and it's exactly how those problems get missed.

The scenario

A machine shop anodises aluminium brackets for an aerospace customer, whose spec requires a coating thickness of 25 µm ± 5 µm (20.0 to 30.0 µm). The inspector measures 30 parts at four locations each with an eddy-current gauge, giving 120 readings.

The report is a 6-page PDF: a cover page, then ruled tables on pages 2 to 6 with four columns.

Part IDLocationThicknessUnit
BRK-0409Flange A24.5µm
BRK-0409Flange B
BRK-0410Flange C0.98mil

The second row is a skipped reading. The third was taken with the gauge set to imperial: 0.98 mil is about 24.9 µm, so the part is fine, but the number would wreck an average if it slipped in unnoticed.

What the summary page shows

The script adds page 7 to the report. On our sample report it found 116 usable readings, 2 missing values and 2 readings in mils.

ItemResult
Readings in µm116
Minimum19.8 µm (page 4, BRK-0417 Flange C)
Maximum31.4 µm (page 2, BRK-0402 Web)
Mean25.1 µm
Missing valuesPage 3: BRK-0409 Flange B; page 6: BRK-0426 Flange B
Unexpected unitsPage 3: BRK-0410 Flange C, 0.98 mil; page 3: BRK-0411 Flange B, 1.03 mil

The mean sits comfortably in spec, but both extremes fall just outside 20 to 30 µm. That's the first thing the reviewer needs to know, and the page reference takes them straight to the row.

How it works with PyMuPDF

The script does four things, each a few lines of PyMuPDF.

  1. Find the tables. page.find_tables() detects ruled tables on each page, and table.extract() returns their cells as lists of strings. No coordinates or regular expressions needed.
  2. Keep only measurement tables. A table counts if its header row has the value column ("Thickness") and the unit column ("Unit"). Every row keeps its page number, so the summary can point back to it.
  3. Sort each reading. A cell that won't parse as a number is missing. A number in another unit is flagged. Everything else goes into the statistics.
  4. Append a page. doc.new_page() matches the report's page size, and page.insert_htmlbox() lays out the summary from a few lines of HTML and CSS, then doc.save() writes the result.

The full, tested script is in the companion cookbook recipe.

Three design decisions

Flag units, don't convert them. Converting 0.98 mil to 24.9 µm is easy, but a unit mismatch can mean a mis-configured gauge, which may affect other readings too. The script excludes those readings from the statistics and lists them, so a person decides.

Show where the extremes are. A bare minimum of 19.8 µm tells the reviewer something is out of spec. Adding "page 4, BRK-0417 Flange C" tells them which part to quarantine.

Append, don't create a separate file. The customer archives one PDF per batch. Keeping the summary inside the report means the evidence and the conclusion always travel together.

Beyond coating thickness

The same pattern fits any report where readings sit in tables across pages: tensile strength in MPa on material test certificates, concrete cover in mm on site inspection records, gas concentrations in ppm on environmental monitoring logs, or calibration results. Change the column name and the unit, and the script works unchanged.

For the full script, a sample report to test it on, and notes on adapting it, see the cookbook recipe Turning a PDF Measurement Report into a Reviewable Summary.


Discuss This Article with the Community

Have a question, a different approach, or something you built after reading this? Share it on the forum or join the Discord, we'd love to hear from you.

PyMuPDF Logo

© 2026 Artifex Software Inc. All rights reserved.