Documentation
¶
Overview ¶
Package pdf is a self-contained, dependency-free PDF reader that extracts a text-based PDF's content and renders it as Markdown for LLM consumption.
Scope (v1): digital/text-based PDFs. It parses the classic cross-reference table as well as PDF 1.5+ cross-reference streams and compressed object streams, inflates FlateDecode content, interprets the text-showing operators of page content streams, maps character codes to Unicode via ToUnicode CMaps and the standard simple-font encodings, then reconstructs paragraphs, headings and best-effort tables.
Out of scope: scanned/image-only PDFs (no text layer — OCR is not attempted) and encrypted PDFs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEncrypted = errors.New("pdf: encrypted document not supported")
ErrEncrypted is returned when the PDF is encrypted and cannot be unlocked with the empty user password — i.e. it genuinely requires a password (or uses an unsupported security handler). Empty-password/permissions-only encryption is decrypted transparently and does not surface this error.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a parsed PDF file: its cross-reference table, trailer and a cache of resolved indirect objects.
type Name ¶
type Name string
Name is a PDF name object without the leading slash (e.g. "Type", "Font").
type Object ¶
type Object interface{}
Object is any PDF object. The concrete types below form a closed set; callers type-switch over them.
type Result ¶
type Result struct {
Markdown string // rendered Markdown ("" when Scanned)
Pages int // number of pages walked
Scanned bool // true when no extractable text layer was found
}
Result is the outcome of converting a PDF to Markdown.
func ToMarkdown ¶
ToMarkdown parses a PDF and renders its text content as Markdown. It returns ErrEncrypted for encrypted documents. For image-only/scanned PDFs it returns a Result with Scanned=true and empty Markdown (OCR is not attempted).