Metadata-Version: 2.4
Name: ocrmypdf-chromelens-ocr
Version: 1.0.4
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
Dynamic: license-file

# OCRmyPDF-ChromeLens-Ocr

A plugin for [OCRmyPDF](https://github.com/ocrmypdf/OCRmyPDF) that uses the **Google Lens API** to perform Optical Character Recognition (OCR). 

## Features

-   **High Accuracy**: Leverages Google's advanced Lens models.
-   **Structure Preservation**: Correctly handles multi-column layouts and vertical text flows via strict API parsing and rotation-aware sorting.
-   **Smart De-hyphenation**: Merges words broken across lines while respecting punctuation dashes.

***

## Installation

### Prerequisites
You must have `ocrmypdf` installed.

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

### Install from Pip
```bash
pip install ocrmypdf-chromelens-ocr
```

## Usage

To use this engine, pass the plugin name to OCRmyPDF. You generally do not need to specify a language, as Google Lens auto-detects it.

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

### Configuration Options

You can configure the behavior of the plugin using the following command-line arguments:

| Argument | Description | Default |
| :--- | :--- | :--- |
| `--chromelens-no-dehyphenation` | Disables the logic that merges hyphenated words across lines. Useful if you prefer raw output. | Disabled |
| `--chromelens-max-dehyphen-len` | The **maximum** length of word parts allowed for de-hyphenation. If both the prefix (before hyphen) and suffix (after hyphen) are *longer* than this value, the plugin assumes it is a compound word or dash separator and will *not* merge them. | 10 |

**Example: Disable de-hyphenation**
```bash
ocrmypdf --plugin ocrmypdf_chromelens_ocr --chromelens-no-dehyphenation input.pdf output.pdf
```

**Example: Stricter de-hyphenation (only merge very short breaks)**
```bash
ocrmypdf --plugin ocrmypdf_chromelens_ocr --chromelens-max-dehyphen-len 4 input.pdf output.pdf
```

## Credits & Acknowledgements

This project is a Python port and adaptation based on ideas and logic from:

1.  **[chrome-lens-ocr](https://github.com/dimdenGD/chrome-lens-ocr)**:
    -   Provided the critical reverse-engineering of the Google Lens Protobuf API (`v1/crupload`).
    -   Logic for strict layout parsing and request structure.

2.  **[OCRmyPDF-AppleOCR](https://github.com/mkyt/OCRmyPDF-AppleOCR)**:
    -   Provided the architectural inspiration for creating an OCRmyPDF plugin that offloads recognition to an external engine.

## Disclaimer

This software is for educational purposes. It uses an undocumented private API from Google. 
-   **Privacy**: Your images are uploaded to Google servers. Do not process sensitive/confidential data.
-   **Stability**: The API may change or break at any time without notice.
-   **Rate Limits**: Excessive use may result in your IP being temporarily blocked by Google.

## License

MIT License
