Batch processing of images
This guide explains how to use UniPDF's OCR capabilities to process multiple images concurrently.
This guide demonstrates how to process multiple images concurrently using UniPDF’s OCR feature. The OCR process is performed by an external OCR service that UniPDF communicates with via HTTP. For this guide, we will use the open-source UniDoc OCR server.
Sample Input
- Sample image #1

- Sample image #2

- Sample image #3

Before you begin
You should get your API key from your UniCloud account.
If this is your first time using UniPDF SDK, follow this guide to set up a local development environment.
You also need to have the UniDoc OCR server running.
First, clone the ocrserver repository:
git clone https://github.com/unidoc/ocrserver.git
Then, navigate to the ocrserver directory and run the server using Docker Compose:
cd ocrserver
docker-compose up
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unipdf-examples.git
Navigate to the ocr folder in the unipdf-examples directory.
cd unipdf-examples/ocr
How it works
The ocr_batch.go example demonstrates how to process multiple images concurrently.
The init function loads the metered license key. The main function takes multiple image file paths as command-line arguments.
The OCROptions are configured to connect to the OCR server.
The client.BatchProcessFiles method is called with the list of file paths. This method processes the images in parallel and returns a list of results.
The results are then iterated and the extracted text for each file is printed to the console. A summary of the batch operation is also displayed.
Run the code
Run the code with multiple image files as input:
go run ocr_batch.go /path/to/image1.png /path/to/image2.jpg
Sample Output
Processing 3 files...
--- Results for sample.png ---
Extracted text from sample.png:
{
"result": "Secure by\n\n°\ndesign\nEvery release of our libraries is automatical-\nly tested against known vulnerabilities and\ndo not pass unless everything is remediat-\ned. All changes are carefully reviewed by\nour team.",
"version": "0.2.0"
}
--- Results for sample2.png ---
Extracted text from sample2.png:
{
"result": ".\nFastest time\nto deployment\nOur SDKs libraries are flexible and devel-\noped to solve common problems. We pro-\nvide high level interfaces for common\nproblem solving and lower level interfaces\nfor less generic tasks.",
"version": "0.2.0"
}
--- Results for sample3.png ---
Extracted text from sample3.png:
{
"result": "Pure Go PDF and\n\n° ° .\nOffice libraries\nUniPDF and UniOffice are all in Pure go\nmeaning you can build your applications\neasily, cross-compile across platforms and\nenjoy all the advantages of Golang.",
"version": "0.2.0"
}
--- Summary ---
Successfully processed: 3 files
Failed to process: 0 files
Total files: 3