extraction

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSupported is returned when an operation (e.g. Image) is not
	// available for a given format.
	ErrNotSupported = errors.New("extraction: operation not supported for this format")

	// ErrUnsupportedFormat is returned by Open when the file extension is
	// not recognised.
	ErrUnsupportedFormat = errors.New("extraction: unsupported file format")
)

Functions

func ExtractText

func ExtractText(path string) (string, error)

ExtractText extracts all text from a document, concatenating every page. The result is sanitised with strings.ToValidUTF8.

func IsDocumentContentType

func IsDocumentContentType(contentType string) (ext string, ok bool)

IsDocumentContentType checks whether the given Content-Type header value corresponds to a supported document format. It returns the file extension and true if so, or ("", false) otherwise.

func IsDocumentFile

func IsDocumentFile(path string) bool

IsDocumentFile returns true for document formats supported by the extraction package.

func IsPDFFile

func IsPDFFile(path string) bool

IsPDFFile returns true if the file is a PDF.

func IsPlainTextFile

func IsPlainTextFile(path string) bool

IsPlainTextFile reports whether path has a known plain-text extension.

func ReadTextFile

func ReadTextFile(path string) (string, error)

ReadTextFile reads a plain-text file and returns its content coerced to valid UTF-8. HTML/RTF are returned verbatim (no tag stripping) — a documented v1 limit.

Types

type Document

type Document interface {
	// NumPage returns the number of logical pages (sheets, slides, chapters).
	NumPage() int

	// Text returns the text content of page pageIndex (0-based).
	Text(pageIndex int) (string, error)

	// Image renders page pageIndex as an image.
	// Returns ErrNotSupported for formats that cannot render pages.
	Image(pageIndex int) (image.Image, error)

	// Close releases all resources held by the document.
	Close() error
}

Document provides page-oriented access to text and rendered images.

func Open

func Open(path string) (Document, error)

Open opens a document at path and returns a Document whose concrete type is chosen by file extension.

Jump to

Keyboard shortcuts

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