Skip to main content

Convert PDF to Editable PDF Using OCR

PDF4me Convert PDF to Editable PDF using OCR is a REST endpoint that makes scanned PDFs searchable and editable. POST a Base64 PDF to /api/v2/ConvertOcrPdf, choose Draft or High quality, and the OCR engine writes a real text layer into the document. The response returns the finished PDF as Base64 JSON, ready to decode and save.

What this endpoint does

Takes an image-based or scanned PDF and returns the same document with recognized, selectable text. qualityType switches between a fast single pass (Draft, 1 API call per file) and per-page recognition (High, 2 API calls per page), while ocrWhenNeeded skips pages that are already searchable. The output arrives as a Base64 docContent field in a JSON response, or via a Location poll URL on 202.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog

Authenticating Your API Request

Every PDF4me REST call must include your API key in the Authorization header as Basic auth. Get or rotate your key from the developer dashboard.

Endpoint

POST/api/v2/ConvertOcrPdf

Important Facts You Should Not Miss

Mixed field types: strings AND booleans
ocrWhenNeeded and outputFormat are the STRINGS "true" / "false", while isAsync and mergeAllSheets are JSON booleans. This mirrors the official code samples; mixing them up is a common cause of 400 errors.
The response is JSON, not raw bytes
A 200 response carries docName plus docContent, the finished PDF as a Base64 string. Decode docContent before saving. Do not write the response body to disk as-is.
Draft and High are billed differently
Draft costs 1 API call per file; High costs 2 API calls per page and is the mode built for scans. Keep ocrWhenNeeded: "true" so already-searchable pages are skipped instead of re-processed.

HTTP setup

Method: POST
URL: https://api.pdf4me.com/api/v2/ConvertOcrPdf
Content-Type: application/json
Authorization: Basic <your PDF4me API key>

Send isAsync: true in the body. 200 returns JSON with the Base64 docContent. 202 returns a Location header with a poll URL; GET that URL with the same Authorization header until it returns 200 with the JSON result.

How do you make a scanned PDF searchable?

A scanned PDF is just pictures of pages; nothing is selectable and nothing matches a text search. OCR (optical character recognition, see the overview of how OCR works) reads each page image and writes the recognized words into the file as a real text layer. After conversion the document behaves like a born-digital PDF: search, copy, and screen readers all work, and it is ready for downstream steps like PDF/A archiving or find-and-replace.

Draft vs HighDraftHigh
Best forNormal PDFs that mostly have a text layerScanned or image-based documents
Cost1 API call per file2 API calls per page
RecognitionLight passFull per-page OCR
Pair withocrWhenNeeded: "true" to skip searchable pageslanguage when text comes back garbled

API body fields

ParameterRequiredTypeWhat it doesExample
docContentRequiredstringBase64-encoded bytes of the source PDF. Strip any data:application/pdf;base64, prefix before posting.JVBERi0xLjcK...
docNameRequiredstringSource filename including the .pdf extension. Used for the output docName.scanned-contract.pdf
qualityTypeRequiredstringDraft for normal PDFs (1 API call per file). High for scanned documents (2 API calls per page).High
ocrWhenNeededRequiredstringThe string "true" skips pages that already have a searchable text layer; "false" forces OCR on every page."true"
outputFormatRequiredstringOutput format flag, sent as the string "true" in the official samples."true"
languageConditionalstringLanguage of the source text (English, Spanish, French, German, and others). Set only when the recognized output is garbled; otherwise let the engine detect it.English
mergeAllSheetsOptionalbooleanJSON boolean carried by the official samples; relevant to sheet-based sources.true
isAsyncOptionalbooleantrue enables the 202 + Location polling pattern, recommended for large scans.true

Sample payloads

High mode. scanned document with OCR

{
"docContent": "JVBERi0xLjcKJcfsj6IKNSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZw...",
"docName": "scanned-contract.pdf",
"qualityType": "High",
"ocrWhenNeeded": "true",
"language": "English",
"outputFormat": "true",
"isAsync": true
}

Draft mode. mixed document, skip searchable pages

{
"docContent": "JVBERi0xLjcKJcfsj6IKNSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZw...",
"docName": "mixed-report.pdf",
"qualityType": "Draft",
"ocrWhenNeeded": "true",
"outputFormat": "true",
"isAsync": true
}

Postman collection tips

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON. Copy a payload above and replace docContent with your Base64. Keep the quotes around "true" for ocrWhenNeeded and outputFormat.
Response
The 200 body is JSON. Copy the docContent value and Base64-decode it to get the PDF. If 202, GET the Location URL with the same Authorization until 200.
Quality
Use High for scans and expect 2 API calls per page. Draft is enough when most pages already have selectable text.

curl example

curl -X POST https://api.pdf4me.com/api/v2/ConvertOcrPdf \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"docContent": "'"$(base64 -w 0 scanned-contract.pdf)"'",
"docName": "scanned-contract.pdf",
"qualityType": "High",
"ocrWhenNeeded": "true",
"outputFormat": "true",
"isAsync": true
}' | python -c "import sys, json, base64; open('searchable.pdf','wb').write(base64.b64decode(json.load(sys.stdin)['docContent']))"

What does the API return?

JSON, not raw file bytes. Decode the docContent field to get the finished PDF.

FieldTypeWhat it contains
docName (HTTP 200)StringThe output PDF filename, derived from the docName you sent.
docContent (HTTP 200)String (Base64)The searchable, editable PDF encoded as Base64. Decode to bytes and save with a .pdf extension.
Location header (HTTP 202)String (URL)Poll URL for an async job that is still running. GET it with the same Authorization header; the official samples poll every 10 seconds, up to 20 retries.
Poll response (HTTP 200)JSONThe same docName + docContent JSON, returned once processing completes.

Code samples

Working end-to-end implementations, each with a sample scanned PDF and the exact payload from this page:

FAQ

How do you make a scanned PDF searchable?+
Run it through OCR. POST the Base64 PDF to /api/v2/ConvertOcrPdf with qualityType High and ocrWhenNeeded "true"; the engine recognizes the text on each scanned page and writes a searchable, selectable text layer into the returned PDF.
Is the response the PDF file itself?+
No. ConvertOcrPdf returns JSON: a docName field and a docContent field holding the output PDF as a Base64 string. Decode docContent to bytes before saving the file.
What does ocrWhenNeeded do?+
Set to the string "true", it skips recognition on pages that already have a searchable text layer, saving processing on mixed documents. Set to "false", every page is OCR-processed regardless.
Which quality mode should I use, Draft or High?+
Draft costs 1 API call per file and suits normal PDFs. High costs 2 API calls per page and is built for scanned documents where every page needs recognition. Use High whenever the source is a scan or photo.
Why are some fields strings and others booleans?+
That is the contract the official code samples ship: ocrWhenNeeded and outputFormat are the strings "true" or "false", while isAsync and mergeAllSheets are JSON booleans. Sending the wrong type is a common cause of 400 errors.
The recognized text is garbled. What now?+
Set the language field to match the document (English, Spanish, French, German, and others) and rerun. Language only needs to be set when automatic detection gets it wrong.
Does OCR change how the pages look?+
No. The text layer is added behind the page image, so the visual appearance stays identical while search, selection, and copy start working.
Can I OCR a PDF and then extract its tables to Excel?+
Yes, but you do not need two calls: the Convert PDF to Excel endpoint runs OCR itself when you set its qualityType to High. Use ConvertOcrPdf when the deliverable should stay a PDF.

Same task on other platforms

Get Help