pdftext

package
v2.17.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package pdftext extracts the text layer of a pdf, decoding composite font strings through each font's ToUnicode map

It exists because uploads are validated locally before any model call, and pdfcpu parses a pdf without extracting text. Reading the string operands directly is not enough: a report exported from Word uses subset fonts with Identity-H encoding, so its content streams carry two byte glyph ids rather than characters, and only the font's ToUnicode map turns those back into text

Index

Constants

View Source
const ContentType = "application/pdf"

ContentType is the mime type of a pdf

Variables

This section is empty.

Functions

func IsContentType

func IsContentType(mimeType string) bool

IsContentType reports whether a mime or content type is a pdf, ignoring parameters and case

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is an opened pdf with its page count and per-page text extraction

func Open

func Open(ctx context.Context, pdf []byte) (*Document, error)

Open reads and validates the pdf once so page counting and text extraction share the parse

func (*Document) PageCount

func (d *Document) PageCount() int

PageCount returns the number of pages in the document

func (*Document) Text

func (d *Document) Text(ctx context.Context) []byte

Text returns the text of every page, cleaned of layout padding. Pages that cannot be read are skipped

Directories

Path Synopsis
Package pdftest builds small pdfs in memory for tests that need a real text layer
Package pdftest builds small pdfs in memory for tests that need a real text layer

Jump to

Keyboard shortcuts

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