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 ¶
const MaxBytes = 50 << 20
Largest document converted, in bytes
Variables ¶
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.
Types ¶
type Error ¶
type Error struct{ Message string }
Failure the model reads: why a document could not be rendered as text
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reads documents, keeping the converter it compiles once for every later call
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