document

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 43 Imported by: 0 modules, 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 document renders document files as text: notebooks, Word, Excel and PowerPoint files old and new, OpenDocument, RTF, EPUB, PDF and SQLite databases

Index

Constants

View Source
const MaxBytes = 50 << 20

Largest document converted, in bytes

Variables

View Source
var ErrNotDocument = errors.New("not a document anydoc reads")

Bytes that neither their content nor their name mark as a document the converter reads

Functions

func Is

func Is(data []byte, name string) bool

Whether the bytes or the name's extension mark a document Extract reads. The bytes may be only the leading ones of a file

func LocalOCR

func LocalOCR(env map[string]string) bool

Whether the search path of the environment, this machine's when nil, has every tool local OCR of scanned PDF pages needs

Types

type Error

type Error struct{ Message string }

Failure the model reads: why a document could not be rendered as text

func (*Error) Error

func (e *Error) Error() string

type Reader

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

Reads documents, keeping the converter it compiles once for every later call

func New

func New() *Reader

func (*Reader) Extract

func (r *Reader) Extract(ctx context.Context, data []byte, name string, using Using) (string, error)

Text of the document as Markdown, the name giving its extension and the path shown in notes. Notebooks, docx, xlsx and SQLite databases have readers of their own, everything else goes through the converter, which tells the format from the content first. A *Error says why the document could not be read, ErrNotDocument that it is no document at all

func (*Reader) Pages

func (r *Reader) Pages(ctx context.Context, data []byte, name string, first, last int, using Using) (string, error)

Text of the pages from first to last of a PDF, each headed by its number: pdftotext's, page by page, where it is on the search path of the read; else each page asked for taken out of the PDF as a file of its own (split.go) and read by the converter, which reads a PDF whole and marks no page, a page without a text layer going to OCR as a whole document does. A PDF whose structure can't be read is given whole, said so with why. A *Error says why there is none

type Using

type Using struct {
	// Reads a PDF without a text layer through a hosted service, tried before local OCR; nil when there is none
	Parse func(ctx context.Context, data []byte, filename string) (string, error)
	// Environment of the commands local OCR runs, the session's own, which their search path is looked up in; this machine's variables
	// alone when nil
	Env map[string]string
	// Folder the read's passing files go in, the profile's scratch folder; the system's own when empty
	Scratch string
}

What a read of a document runs on for the session it reads for

Jump to

Keyboard shortcuts

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