- Get started
- Overview
- Getting started
- Processing a PDF
- Common functions
- Error handling
- Organize
-
Merge PDF
-
Split PDF
-
Smart Split PDF (AI)
-
Rotate PDF
-
Add page numbers
- Optimize
-
Compress PDF
-
Repair PDF
-
PDF to PDF/A
-
Validate PDF/A
- Convert
-
Office to PDF
-
HTML to PDF
-
Images to PDF
-
PDF to JPG
- Edit and secure
-
Edit PDF
-
Watermark PDF
-
Protect PDF
-
Unlock PDF
- AI and data
-
OCR PDF
-
Extract text
-
PDF to Markdown (AI)
-
AI Summarizer (AI)
-
Detect forms (AI)
- No matches.
Resources
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();// Create a new task
var taskOcr = api.CreateTask<PdfocrTask>();
// Add files to task for upload
var file = taskOcr.AddFile("document.pdf");
// Execute the task
taskOcr.Process();
// Download the file
taskOcr.DownloadFile();# Under constructionconst task = ilovepdf.newTask('pdfocr') as PdfOcrTask;
task.start()
.then(() => {
const file = new ILovePDFFile('path/to/file/document.pdf');
return task.addFile(file);
})
.then(() => {
return task.process({ ocr_languages: ['eng'] });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});PHP library ilovepdf/ilovepdf-php
composer require ilovepdf/ilovepdf-php.NET library ilovepdf/ilovepdf-net
dotnet add package ILove_PDFRuby library ilovepdf/ilovepdf-ruby
gem install ilovepdfNode.js library ilovepdf/ilovepdf-nodejs
npm install @ilovepdf/ilovepdf-nodejsOCR 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 withocr_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, soocr_languagesis 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) orgreyscale.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/$TASKAll the parameters are described in the API reference.