OCR PDF Guide

Learn to convert scanned PDF files to searchable PDF files using the OCR PDF REST API.

New to the API? Start with Processing a PDF: every tool guide builds on its task flow.

Basic OCR PDF

Making a scanned PDF searchable is very easy, as you will see in this code:

Basic OCR PDF
// Create a new task
$myTask = $ilovepdf->newTask('pdfocr');
// file var keeps info about server file id, name...
// it can be used later to cancel file
$file = $myTask->addFile('/path/to/file/document.pdf');
// process files
$myTask->execute();
// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

OCR modes

The ocr_mode parameter of the process request selects the OCR engine:

  • Standard (ocr_mode=standard, the default): every page is rendered as an image and recognized in the languages you choose with ocr_languages (up to 3; English is always added). 5 credits per page. The best choice for clean scans and digital documents.
  • Advanced (ocr_mode=advanced): an AI-based OCR engine for difficult documents: photos of pages, low-quality or skewed scans, curved book pages, mixed layouts and rotated text. It detects the language by itself, so ocr_languages is not used. 20 credits per page.

Both modes can use your monthly free credits. See the credits per tool.

Improve difficult scans

These optional parameters clean up the pages before recognition:

  • auto_rotate: detect the orientation of every page and rotate it (90, 180 or 270 degrees).
  • deskew: straighten pages scanned slightly tilted.
  • dewarp: correct curved or distorted pages, such as book scans or photos of pages.
  • color: original (default), bn (black and white) or greyscale.
  • dpi: resolution used to render the pages, 72 to 600 (default 300).
  • textline_orientation: detect the orientation of individual text lines (advanced mode only).

Advanced OCR PDF

The official libraries don't have methods for ocr_mode and these options yet, so send them in the process request of the REST API. The rest of the task is the same as any other tool:

Advanced OCR PDFcURL
# 1. Start a PDF OCR task: returns the assigned server and the task ID
curl -H "Authorization: Bearer $TOKEN" https://api.ilovepdf.com/v1/start/pdfocr

# 2. Upload the scan to the assigned server: returns server_filename
curl -H "Authorization: Bearer $TOKEN" -F task=$TASK -F file=@scan.pdf https://$SERVER/v1/upload

# 3. Process with the advanced (AI) OCR engine and clean up the pages first
curl -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"task":"'$TASK'","tool":"pdfocr","files":[{"server_filename":"'$FILE'","filename":"scan.pdf"}],
       "ocr_mode":"advanced","auto_rotate":true,"deskew":true,"dewarp":true,"textline_orientation":true}' \
  https://$SERVER/v1/process

# 4. Download the searchable PDF
curl -H "Authorization: Bearer $TOKEN" -o scan-ocr.pdf https://$SERVER/v1/download/$TASK

All the parameters are described in the API reference.