document

package
v2.25.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package document reads the files a model is given: PDF, Word and Excel files and text as text, images as images, and the scanned pages of a PDF as images.

Index

Constants

View Source
const (
	// MaxFileBytes bounds one file.
	MaxFileBytes = 50 << 20
	// MaxImages bounds the images a model is given at once, image files and
	// scanned pages together.
	MaxImages = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Name is the file's base name.
	Name string
	// Text is the file's text; a PDF's text is in Pages instead.
	Text string
	// Image is an image file, scaled to fit a model.
	Image *Image
	// Pages are a PDF's pages.
	Pages []Page
}

File is a file as a model takes it.

func Read

func Read(ctx context.Context, path string) (File, error)

Read reads one file. PDF text is read with PDFium, the PDF engine of Chrome, so the embedded fonts Japanese documents use are read; a page with no text is rendered to an image. Word and Excel files are read as text, a paragraph or row a line; text files in UTF-8 or Shift_JIS; images are scaled down when larger than a model takes.

func (File) Images

func (f File) Images() []Image

Images returns the file's images: the image file, or the scanned pages.

type Image

type Image struct {
	// MediaType is the image's IANA media type, such as image/png.
	MediaType string
	Data      []byte
}

Image is an encoded image.

type Page

type Page struct {
	Text  string
	Image *Image
}

Page is one page of a PDF: its text, or its image when it holds none.

Jump to

Keyboard shortcuts

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