← Atlas

Project Record

PDF Parser Using sed Commands

Command-template workflow for extracting text from PDFs and normalizing output through sed filters.

pdfshellparsing

Context

Many internal reports and disclosures are PDF-only. Extracting text for search, parsing, or downstream pipelines usually requires a reliable PDF-to-text step plus normalization (whitespace, line breaks, encoding). A command-template workflow using pdftotext and sed keeps the pipeline simple and auditable without heavy dependencies.

Problem

Raw PDF text extraction is messy: inconsistent spacing, stray line breaks, and non-ASCII characters. We need a repeatable pipeline that (1) extracts text with layout preserved where useful, (2) normalizes spaces and blank lines, and (3) optionally applies further sed-style rules for field extraction or cleanup. The solution should work in scripts and in an internal tool that previews or applies the same logic to pasted text.

Shell Pipeline

pdftotext -layout report.pdf - | sed -E 's/[[:space:]]+/ /g' | sed '/^$/d'

First stage extracts text; subsequent sed steps collapse whitespace and remove empty lines. Additional rules can strip headers, normalize dates, or extract tables.

Implementation

Trade-offs

Layout extraction is best-effort; complex tables or multi-column PDFs may need dedicated tools (e.g. tabula, camelot). Sed is powerful but brittle for highly variable formats; for production parsing, consider structured extraction or ML once the pipeline is stable.

Related Work