Documentation
¶
Overview ¶
Package pdf extracts text from PDF files, with glyph positions.
Extract returns per-page positioned glyphs; Page.Text reconstructs plain text by clustering glyphs into lines and inserting word spacing derived from glyph gaps and font metrics.
The package implements its own content-stream lexer, interpreter, and font decoding on top of the object-parsing primitives of github.com/ledongthuc/pdf (BSD-3-Clause). That library's built-in text extraction has gaps that matter on real-world files: it never descends into Form XObjects (losing all text in e.g. Google Docs exports), it ignores /ToUnicode when an /Encoding dictionary is present, it tracks positions only through the Tm operator, its lexer spins forever on tokens that straddle /Contents array segments, and it has no defenses against decompression bombs, stalled filter chains, or cyclic page trees. This package addresses all of the above and is validated against corpora of real-world documents; replacing the remaining object layer with a native implementation is on the roadmap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
Pages []Page
}
Document is the extraction result for a whole file.
type Glyph ¶
type Glyph struct {
Text string // decoded text, non-empty
X, Y float64 // origin
Advance float64 // horizontal advance
Size float64 // effective font size
}
Glyph is one decoded glyph (or glyph cluster) with its position in unrotated page space.