pdftext

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pdftext reads PDF files: whether data is one, its page count and its text, page by page (spec_images_011). Models that can't read a PDF get its text; read_file shows it. Reading is defensive: the parser's panics become errors and a deadline bounds a pathological file. In the programs (UseHelper), the text is read in a child process that's killed at the deadline, so a page the parser loops on, a crash or a blow-up ends with it.

Index

Constants

View Source
const MIME = "application/pdf"

MIME is a PDF's media type.

View Source
const Timeout = 20 * time.Second

Timeout bounds reading one file's text.

Variables

View Source
var ErrNotPDF = errors.New("not a PDF")

ErrNotPDF is returned for data that isn't a PDF.

Functions

func IsPDF

func IsPDF(data []byte) bool

IsPDF reports whether data starts like a PDF: the "%PDF-" header within its first kilobyte, as readers allow.

func IsPDFPath

func IsPDFPath(p string) bool

IsPDFPath reports whether a file name ends in .pdf.

func MaybeServe added in v0.3.0

func MaybeServe()

MaybeServe answers as the helper and exits, when this process was started as one; otherwise it returns at once.

func Pages

func Pages(data []byte) (n int, err error)

Pages counts a PDF's pages.

func Text

func Text(ctx context.Context, data []byte, maxChars int) (string, int, error)

Text is a PDF's text, each page headed "--- Page N ---", and its page count. A scanned page has no text to give. maxChars (> 0) cuts the text short with a note saying so.

func UseHelper added in v0.3.0

func UseHelper()

UseHelper makes Text read in a child process: this program, run again with helperEnv set, which MaybeServe answers. A program calls both, MaybeServe first, at the start of main. Without it (tests, libraries) Text reads in-process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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