document

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 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 Cache

func Cache() string

Cache returns the folder in the user's cache folder where the converter's compiled native code is kept. It is empty when the system has no user cache folder.

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)

Pages returns the text of a PDF's pages from first to last, each headed by its page number. It uses pdftotext page by page when pdftotext is on the read's search path. Otherwise it splits each requested page into its own PDF file (split.go) and reads that file with the converter, because the converter reads a full PDF without page markers. A page without a text layer goes to OCR, the same as a full document. For a PDF with an unreadable structure, it returns the full text with a note that gives the reason. A *Error gives the reason when there is no text.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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