pdftext

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pdftext extracts plain text from PDFs that carry a real text layer (i.e. not a scan) without any external service. It exists so readPDFFile has a better no-docling fallback than raw base64 pass-through: most PDFs - reports, exports, invoices - are text-native, and pdfcpu (already a dependency here) only exposes page/content-stream manipulation, not decoded text.

Index

Constants

View Source
const MinCharsPerPage = 20

MinCharsPerPage is the threshold below which extracted text is treated as "not really there" - a scanned/image-only PDF will still yield a handful of stray characters from stamps or embedded metadata, but nowhere near this per page on average. Below it, callers should prefer OCR (docling) or the base64/vision fallback instead of trusting this near-empty text.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Text      string
	PageCount int
	// Sparse is true when the extracted text is too little relative to the
	// page count to be a real text layer - most likely a scanned PDF.
	Sparse bool
}

Result holds the outcome of a native PDF text extraction attempt.

func Extract

func Extract(data []byte) (*Result, error)

Extract reads a PDF's embedded text layer. It does not attempt OCR: a scanned PDF with no text layer will return a Sparse result with little or no text, not an error - callers decide what to do next (try docling, or fall back to sending the raw PDF to a vision-capable model).

Jump to

Keyboard shortcuts

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