Aller au contenu principal

Convertir PDF à modifier PDF En utilisant OCR

PDF4me Convertir PDF à modifier PDF en utilisant OCR est un REST point de terminaison qui effectue la numérisation PDFs consultable et modifiable. POST un Base64 PDF à /api/v2/ConvertOcrPdf, choisissez Brouillon ou Haute qualité, et le OCR Le moteur écrit une véritable couche de texte dans le document. La réponse renvoie le document final. PDF comme Base64 JSON, prêt à décoder et à sauvegarder.

Que fait ce point de terminaison ?

Prend une image ou une image numérisée PDF et renvoie le même document avec un texte reconnu et sélectionnable. qualityType alterne entre un passage unique rapide (Brouillon, 1 API appel par fichier) et reconnaissance par page (Haut, 2 API appels par page), tandis que ocrWhenNeeded sauts pages qui sont déjà consultables. Le résultat arrive sous forme de Base64 docContent champ dans un JSON réponse, ou via une Location sondage URL le 202.

Articles de blog connexes
Il n'y a pas encore d'article de blog consacré à cette fonctionnalité — à venir prochainement.
En attendant, n'hésitez pas à consulter le blog de PDF4me pour découvrir des tutoriels et des procédures de travail adaptés à toutes les plateformes.
Consultez le blog

Authentification de votre API Demande

Chaque PDF4me REST L'appel doit inclure votre API clé dans le Authorization En-tête : Authentification de base. Récupérez ou renouvelez votre clé depuis le tableau de bord développeur.

Point de terminaison

POST/api/v2/ConvertOcrPdf

Informations importantes à ne pas manquer

Types de champs mixtes : chaînes de caractères ET booléens
ocrWhenNeeded et outputFormat sont les CORDES "vrai" / "FAUX", alors que isAsync et mergeAllSheets sont JSON booléens. Ceci est conforme aux exemples de code officiels ; les confondre est une cause fréquente d’erreurs 400.
La réponse est JSON, pas des octets bruts
Une réponse de 200 personnes porte docName plus docContent, le fini PDF comme un Base64 chaîne. Décoder docContent avant l'enregistrement. Ne pas écrire le corps de la réponse tel quel sur le disque.
Les formules Draft et High sont facturées différemment.
Coût du brouillon 1 API appel par dossier ; Coûts élevés 2 API appels par page et est le mode conçu pour les numérisations. Conserver ocrWhenNeeded: "vrai" donc déjà consultable pages sont ignorées au lieu d'être retraitées.

HTTP installation

Méthode: POST
URL: https://api.pdf4me.com/api/v2/ConvertOcrPdf
Type de contenu : application/json
Authorization: Basique <votre PDF4me API clé>

Envoyer isAsync: vrai dans le corps. 200 retours JSON avec le Base64 docContent. 202 renvoie un Location en-tête avec un sondage URL; GET que URL avec le même Authorization en-tête jusqu'à ce qu'il renvoie 200 avec le JSON résultat.

Comment réaliser un scan PDF consultable ?

Un scan PDF ce ne sont que des photos de pages; rien n'est sélectionnable et rien ne correspond à une recherche textuelle. OCR (reconnaissance optique de caractères, voir la aperçu de la façon OCR travauxLe logiciel lit l'image de chaque page et inscrit les mots reconnus dans le fichier sous forme de véritable couche de texte. Après conversion, le document se comporte comme un document numérique natif. PDFLa recherche, la copie et les lecteurs d'écran fonctionnent tous, et le système est prêt pour les étapes suivantes, comme… PDF/A archivage ou rechercher et remplacer.

Draft vs HighBrouillonHaut
Idéal pourNormale PDFs qui possèdent pour la plupart une couche de texteDocuments numérisés ou sous forme d'images
Coût1 API appel par fichier2 API appels par page
ReconnaissancePassage légerPleine page OCR
Associer àocrWhenNeeded: "true" ignorer les éléments consultables pageslanguage lorsque le texte est renvoyé brouillé

API champs corporels

ParamètreRequisTaperCe que cela faitExemple
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

Exemples de charges utiles

Mode élevé. Document numérisé avec OCR

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

Mode brouillon. Document mixte, recherche possible sans interruption. pages

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

Conseils pour la collecte par le facteur

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.

Exemple curl

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']))"

Que signifie le API retour?

JSON, et non les octets bruts du fichier. Décodez le docContent champ pour obtenir le fini PDF.

ChampTaperCe qu'il contient
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.

Exemples de code

Des implémentations complètes et fonctionnelles, chacune avec un exemple scanné PDF et la charge utile exacte de cette 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.

Actions connexes

Même tâche sur d'autres plateformes

Obtenez de l'aide