Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCR in Python with Apryse

Do OCR in Python with the Apryse Server SDK: turn a scanned PDF or image into a searchable PDF, and print the extracted text.

Prerequisites (requirements.txt)

apryse-sdk
python-dotenv

Configure Python Environment

Create and activate a virtual environment, then install the Apryse SDK from the dedicated index to enable OCR capabilities in Python.

python3 -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
python -m pip install apryse-sdk --extra-index-url=https://pypi.apryse.com

Download Apryse OCR Module

  1. Obtain a free trial license key for the Apryse Server SDK.
  2. Copy the .env.example file and update it with your Server key. cp .env.example .env
  3. Download the Apryse OCR Module for your target operating system.
  4. Copy the contents of the Lib folder from the extracted zip archive into a new Lib folder at the root of the project directory.
  5. Add sample scanned PDFs or images to the project directory (supported file types).

Run the OCR Script

Pass the target file (a scanned PDF or an image) as an argument. Scanned PDFs get OCR'd in place via OCRModule.ProcessPDF; images are converted into a new searchable PDF via OCRModule.ImageToPDF.

python demo.py <path_to_scanned_pdf_or_image>

The script prints a preview of the recognized text to the console and saves a searchable PDF to outputs/<name>_ocr-output.pdf.

How it works

from apryse_sdk import PDFNet, PDFDoc, OCRModule

PDFNet.Initialize(server_key)
PDFNet.AddResourceSearchPath("./Lib/")

doc = PDFDoc(input_path)          # for a scanned PDF
OCRModule.ProcessPDF(doc, None)   # adds a searchable text layer

OCRModule.ImageToPDF(doc, input_path, None)  # alternative: for image input

See demo.py for the full script, including error handling and text extraction.

About

Demo accompanying video on OCR in Python with Apryse

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages