Pdf Processor
Post-Mortem: Diagnosing a PDF Pipeline That Works for Two PDFs and Fails on the Third
TLDR
Stress-testing a 2-column layout detector against a LaTeX paper revealed zero splits, initially blamed on math glyph baseline calibration errors (modeFont vs medianFont). Diagnostic instrumentation proved font baselines diverged by only $0.1\text{pt}$, proving that the failure was caused by single display-math text runs bridging the column gutter ($X \approx 310$). Adding a $vWidth > S \times 4$ filter isolates paragraph text, resolving the defect in two lines.
| Diagnostic Test Case | Font Calibration Divergence | Fallback Gutter Evaluation | Split Detection Result |
|---|---|---|---|
| Unfiltered Fallback | $0.1\text{pt}$ (Negligible) | Blocked by $500\text{px}$ display math | 0 Splits (Defective) |
| Math-Filtered Fallback | $0.1\text{pt}$ (Negligible) | Clear gutter at $X \approx 310$ | 1 Split (Correct) |
Technical diagnostic protocol & findings
- Verify Baseline Calibration: Compare
modeFontvsmedianFontacross pages; reject calibration theories if divergence is $\le 0.5\text{pt}$. - Inspect Raw Item Extents: Log item width distributions (
vWidth) to detect anomalously wide text blocks. - Isolate Gutter-Crossing Noise: Apply scale-relative width thresholds (
vWidth <= S * 4) prior to running candidate coordinate evaluations.
// Scale-Relative Width Pre-Filter for Fallback Column Detection
export function isolateNarrowParagraphItems(textMeta, bodyFontPt) {
const maxWidthPx = bodyFontPt 4 1.333; // Account for CSS scale factor
return textMeta.filter(item => item.vWidth <= maxWidthPx);
}
Rule of thumb: Instrument diagnostic logging to measure font baseline divergence before refactoring calibration algorithms for multi-column documents.
Read this post in the full Engineering Journal →