Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Extract ¶
func Extract(ctx context.Context, pdfBackend PDFBackend, ocrBackend OCRBackend, filePath string) ([]string, error)
Extract processes a PDF file and returns its extracted text. If an OCRBackend is provided and a page is sparse, it will fall back to OCR.
Types ¶
type OCRBackend ¶
type OCRBackend interface {
// Available returns true if the OCR backend is installed and executable.
Available() bool
// ValidateLang checks if the configured language data is available.
ValidateLang(ctx context.Context) error
// OCRPage performs OCR on the specified image file and returns the extracted text.
OCRPage(ctx context.Context, imagePath string) (string, error)
}
OCRBackend is the interface for performing OCR on images.
type PDFBackend ¶
type PDFBackend interface {
// ExtractText extracts text from the PDF file, returning a slice where each element is a page's text.
ExtractText(ctx context.Context, filePath string) ([]string, error)
// RenderPage renders the specified page (1-indexed) to a temporary image file and returns the path.
RenderPage(ctx context.Context, filePath string, pageNum int) (string, error)
// Close releases any resources associated with the backend.
Close() error
}
PDFBackend is the interface for extracting text and rendering pages from PDF files.
type PDFChunk ¶
PDFChunk represents a chunk of text extracted from a PDF.
func ChunkPages ¶
ChunkPages takes a slice of page texts, strips repetitive headers/footers, drops sparse pages, and splits long pages into smaller overlapping chunks.
type PDFiumBackend ¶
type PDFiumBackend struct {
// contains filtered or unexported fields
}
PDFiumBackend implements PDFBackend using go-pdfium via WASM.
func NewPDFiumBackend ¶
func NewPDFiumBackend() (*PDFiumBackend, error)
NewPDFiumBackend initializes a new PDFium WebAssembly backend.
func (*PDFiumBackend) Close ¶
func (b *PDFiumBackend) Close() error
Close releases the PDFium instance and pool.
func (*PDFiumBackend) ExtractText ¶
ExtractText returns the text of each page in the PDF document as a slice of strings.
func (*PDFiumBackend) RenderPage ¶
RenderPage renders the specified page of a PDF document to a JPEG image file in a temporary directory.
type TesseractBackend ¶
TesseractBackend implements OCRBackend using the tesseract CLI tool.
func NewTesseractBackend ¶
func NewTesseractBackend(binPath, lang string) *TesseractBackend
NewTesseractBackend creates a new TesseractBackend.
func (*TesseractBackend) Available ¶
func (b *TesseractBackend) Available() bool
Available returns true if the tesseract binary is executable.
func (*TesseractBackend) OCRPage ¶
OCRPage performs OCR on the specified image file and returns the extracted text.
func (*TesseractBackend) ValidateLang ¶
func (b *TesseractBackend) ValidateLang(ctx context.Context) error
ValidateLang checks that the configured language data is available.