Documentation
¶
Overview ¶
Package pdfsource extracts local PDF text, hyperlinks and embedded images in pure Go. Document contents are untrusted data, never agent instructions.
Index ¶
Constants ¶
const MaxMappingBytes = 4 << 20
const MaxPDFBytes = 32 << 20
const MaxPages = 10
Variables ¶
This section is empty.
Functions ¶
func SourceHash ¶
Types ¶
type Document ¶
type Document struct {
PageCount int `json:"page_count"`
StartPage int `json:"start_page"`
EndPage int `json:"end_page"`
HasMore bool `json:"has_more"`
Pages []Page `json:"pages"`
}
func Read ¶
Read extracts a 1-based inclusive range of at most ten pages. Zero start means one; zero end means up to ten pages. It never runs subprocesses or follows links. Decoded streams/images and object counts are bounded. Context checks are cooperative: there is no per-call OS memory ceiling or forcible decoder kill.
type Extraction ¶
type FileExtraction ¶
type FileExtraction struct {
Path string `json:"path"`
Bytes int `json:"bytes"`
SourceSHA256 string `json:"source_sha256"`
PageCount int `json:"page_count"`
ReferencedLines int `json:"referenced_lines"`
IgnoredLines int `json:"ignored_lines"`
}
func ExtractFiles ¶
func ExtractFiles(ctx context.Context, root, pdfPath, mappingPath, outputPath string) (*FileExtraction, error)
type IndexedDocument ¶
type IndexedDocument struct {
Version int `json:"version"`
SourceSHA256 string `json:"source_sha256"`
PageCount int `json:"page_count"`
StartPage int `json:"start_page"`
EndPage int `json:"end_page"`
HasMore bool `json:"has_more"`
Pages []IndexedPage `json:"pages"`
}
type IndexedImage ¶
type IndexedPage ¶
type IndexedPage struct {
Number int `json:"number"`
Lines []Line `json:"lines"`
Links []Link `json:"links"`
Images []IndexedImage `json:"images"`
RequiresOCR bool `json:"requires_ocr"`
}
type Link ¶
Link.Text is a best-effort label derived from overlapping text origins. Rect retains the PDF annotation coordinates even when no label is available.
type MappingManifest ¶
type MappingManifest struct {
Version int `json:"version"`
SourceSHA256 string `json:"source_sha256"`
Parts []string `json:"parts"`
}
MappingManifest orders independently saved structural mappings. Parts are relative to the manifest directory and cannot themselves be manifests.
type Placement ¶
Placement is a known image occurrence in unrotated PDF user coordinates. NearbyText is a best-effort heading association, not a semantic role.
type Range ¶
type Range struct {
Page int `json:"page"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
StartColumn int `json:"start_column,omitzero"`
EndColumn int `json:"end_column,omitzero"`
}
Range selects inclusive 1-based lines. Optional columns are 1-based rune positions, inclusive, on the first/last line. Zero means the whole line.
type Selector ¶
type Selector struct {
Ranges []Range `json:"ranges,omitempty"`
Format string `json:"format,omitempty"`
Pattern string `json:"pattern,omitempty"`
Group int `json:"group,omitzero"`
// Link and image address PDF objects directly, never model-written URLs.
Page int `json:"page,omitzero"`
Link int `json:"link,omitzero"` // 1-based annotation index
ImageID string `json:"image_id,omitempty"`
}