pdf

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

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

View Source
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

func Float

func Float(o Object) (float64, bool)

Float returns the numeric value of an Integer or Real, and whether the object was numeric at all.

func Int

func Int(o Object) (int, bool)

Int returns the integer value of an Integer (or truncated Real), and whether the object was numeric.

Types

type Array

type Array []Object

Array is a PDF array object.

type Boolean

type Boolean bool

Boolean is a PDF boolean (true/false).

type Dict

type Dict map[Name]Object

Dict is a PDF dictionary object.

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.

func Parse

func Parse(data []byte) (*Document, error)

Parse reads a PDF file's structure from raw bytes.

func (*Document) Resolve

func (d *Document) Resolve(o Object) Object

Resolve dereferences an indirect reference (recursively for chained refs), returning the concrete object. Non-references are returned as-is.

type Integer

type Integer int64

Integer is a PDF integer object.

type Name

type Name string

Name is a PDF name object without the leading slash (e.g. "Type", "Font").

type Null

type Null struct{}

Null is the PDF null object.

type Object

type Object interface{}

Object is any PDF object. The concrete types below form a closed set; callers type-switch over them.

type Real

type Real float64

Real is a PDF real (floating point) object.

type Reference

type Reference struct {
	Num int
	Gen int
}

Reference is an indirect object reference ("12 0 R").

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

func ToMarkdown(data []byte) (Result, error)

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).

type Stream

type Stream struct {
	Dict Dict
	Raw  []byte
}

Stream is a PDF stream object: its dictionary plus the raw (still-encoded) stream bytes. Decoding happens on demand via the filter pipeline.

type String

type String []byte

String is a PDF string object, already decoded from its literal "(...)" or hexadecimal "<...>" representation into raw bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL