A high-performance Go library and CLI for running Google Chrome Screen AI OCR on-device. This package extracts text from images and PDFs with high precision, generates searchable PDFs (with transparent text layers), and provides built-in cleaning pipelines tailored for legal and general documents.
- 3 Output Formats Simultaneously: Generates Layered PDF (
.pdf), Parsed Text (.txt), and Page-by-Page JSON Array (.json) in a single call. - Indonesian Legal Document Cleaning: Fixes merged legal terms (
DAYAAIR→DAYA AIR), normalizes legal preamble triggers (Menimbang,Mengingat,PASAL), and strips diagonal & JDIH portal watermarks. - Image & PDF Support: Processes PDF files, image files (
.png,.jpg), or in-memory[]image.Imageslices (e.g. rendered viago-fitz). - Silent Native Logs: Suppresses raw C++ glog/TensorFlow Lite log noise at the OS level while offering execution progress metrics (
s,ms,ns). - Zero Environment Variables: Configured via Go Functional Options (
WithModelDir,WithProgress,WithLightMode, etc.).
go get github.com/fuadarradhi/chromeocrSystem Requirement: Requires poppler-utils (pdftoppm) installed on your system to process PDF files.
Run directly from your terminal to process PDF files:
# Process PDF and generate 3 output files (_layered.pdf, .txt, .json)
go run ./cmd/chromeocr --input document.pdf
# Specify explicit output paths
go run ./cmd/chromeocr --input document.pdf --output output.pdf --txt-output output.txt --json-output output.jsonpackage main
import (
"fmt"
"log"
"github.com/fuadarradhi/chromeocr"
)
func main() {
// Initialize Engine
engine, err := chromeocr.New()
if err != nil {
log.Fatal(err)
}
defer engine.Close()
// Process PDF
result, err := engine.ProcessPDF("document.pdf", "document_layered.pdf")
if err != nil {
log.Fatal(err)
}
// Access parsed text and export outputs
fmt.Println(result.FullText)
_ = result.SaveOutputs("document.txt", "document.json")
}engine, err := chromeocr.New()
if err != nil {
log.Fatal(err)
}
defer engine.Close()
page, err := engine.OCRFile("page.png")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Image Dimensions: %dx%d px\n", page.Width, page.Height)
fmt.Println(page.Text())Use this method when PDF pages are pre-rendered in memory for maximum performance:
engine, err := chromeocr.New()
if err != nil {
log.Fatal(err)
}
defer engine.Close() // Single initialization for the entire loop
// inMemoryImages is a slice of image.Image
result, err := engine.ProcessImages(inMemoryImages)
if err != nil {
log.Fatal(err)
}
_ = result.SaveOutputs("output.txt", "output.json")engine, err := chromeocr.New(
chromeocr.WithLightMode(false), // High-accuracy model
chromeocr.WithProgress(func(p chromeocr.PageProgress) {
fmt.Printf("Page %d/%d completed in %v\n", p.PageNum, p.TotalPages, p.Duration)
}),
)Check the example/ directory for runnable implementations:
example/01-pdf-multi-output: PDF processing to 3 simultaneous outputs.example/02-single-image-ocr: Single image file OCR & bounding box geometry.example/03-in-memory-image-loop: In-memory image loop with single engine session (e.g.,go-fitz).example/04-custom-configuration: Functional options & progress callback logger.example/05-legal-document-cleaning: Indonesian legal text cleaning & normalizations.
MIT License