Metadata-Version: 2.4
Name: ocrmypdf-chromelens-ocr
Version: 1.0.7
Summary: OCRmyPDF plugin using Google Lens API for OCR
Author-email: Victor Sakovich <atlantos@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Victor Sakovich
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/atlantos/OCRmyPDF-ChromeLens-Ocr
Project-URL: Bug Tracker, https://github.com/atlantos/OCRmyPDF-ChromeLens-Ocr/issues
Keywords: ocrmypdf,ocr,google-lens,pdf,plugin
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Topic :: Text Processing :: Indexing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ocrmypdf>=16.0.0
Requires-Dist: requests
Requires-Dist: Pillow
Requires-Dist: packaging
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Dynamic: license-file

# OCRmyPDF-ChromeLens-Ocr

OCRmyPDF plugin that uses Google Lens (`v1/crupload`) as OCR backend.

## What It Does

- Sends rasterized page images to Google Lens and parses protobuf response into hOCR + text.
- Preserves hierarchical layout (paragraphs/lines/words), including rotation metadata (`textangle` in hOCR lines).
- Handles word separators from Lens response for better spacing fidelity.
- Includes optional de-hyphenation for line-broken words.
- Tries to preserve superscript glyphs (for example `¹²³`) by overriding OCRmyPDF's NFKC normalization path.

## Installation

Prerequisite: install `ocrmypdf`.

Install from Git:

```bash
pip install git+https://github.com/atlantos/OCRmyPDF-ChromeLens-Ocr.git
```

Install from PyPI:

```bash
pip install ocrmypdf-chromelens-ocr
```

## Usage

Basic usage:

```bash
ocrmypdf --plugin ocrmypdf_chromelens_ocr input.pdf output.pdf
```

Debug dump example:

```bash
ocrmypdf \
  --plugin ocrmypdf_chromelens_ocr \
  --keep-temporary-files \
  --chromelens-dump-debug \
  input.pdf output.pdf
```

## Plugin CLI Options

| Option | Description | Default |
| :--- | :--- | :--- |
| `--chromelens-no-dehyphenation` | Disable de-hyphenation across adjacent lines. | `false` |
| `--chromelens-max-dehyphen-len` | Max prefix/suffix length threshold for de-hyphenation merge. | `10` |
| `--chromelens-dump-debug` | Write raw request/response + parsed layout artifacts next to `*_ocr_hocr.*` temp files. Works only with `--keep-temporary-files`. | `false` |

## Current Implementation Defaults

These are hardcoded in `src/ocrmypdf_chromelens_ocr/plugin.py`:

- Upload format: `JPEG`
- JPEG quality: `95`
- Max upload long edge:
  - OCRmyPDF v16: `1600`
  - OCRmyPDF v17+: `1200`
- Fixed request locale/context:
  - language `en`, region `US`, timezone `America/New_York`
- Chrome-style request headers:
  - `x-browser-channel`, `x-browser-year`, `x-browser-copyright`, `x-browser-validation`

Note: OCRmyPDF language flags (`-l/--language`) are not propagated to Lens request context; Lens auto-detection is relied on.

## Compatibility

- Python `>=3.9`
- OCRmyPDF `>=16.0.0`
- Tested with OCRmyPDF 16 and 17 code paths

## Limitations

- Uses undocumented/private Google API and may break without notice.
- Requires network access and uploads page images to Google servers.
- OCR quality depends on Lens behavior and can vary by document type.
- `generate_pdf()` in the plugin is not implemented; OCR output is produced through hOCR/text path.

## Credits

- [chrome-lens-ocr](https://github.com/dimdenGD/chrome-lens-ocr) for protobuf/API reverse-engineering ideas.
- [OCRmyPDF-AppleOCR](https://github.com/mkyt/OCRmyPDF-AppleOCR) for plugin architecture inspiration.

## License

MIT
