Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chromeocr

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.


🌟 Key Features

  • 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 (DAYAAIRDAYA 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.Image slices (e.g. rendered via go-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.).

📥 Installation

go get github.com/fuadarradhi/chromeocr

System Requirement: Requires poppler-utils (pdftoppm) installed on your system to process PDF files.


🚀 Quick Start & Usage

1. Command Line Interface (CLI)

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.json

2. Usage as a Go Library

A. Processing PDFs (PDF → Searchable PDF + Clean TXT + Page JSON)

package 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")
}

B. OCR for a Single Image File (.png / .jpg)

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())

C. In-Memory Image Loop (Single Engine Session e.g. with go-fitz)

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")

D. Dynamic Options & Execution Progress Metrics

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)
    }),
)

📁 Examples

Check the example/ directory for runnable implementations:


📄 License

MIT License

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages