Zum Hauptinhalt springen

Konvertieren PDF zu bearbeitbar PDF Verwendung OCR

PDF4me Konvertieren PDF zu bearbeitbar PDF Verwendung OCR ist ein REST Endpunkt, der gescannt wird PDFs Suchbar und bearbeitbar. POST A Base64 PDF Zu /api/v2/ConvertOcrPdfWählen Sie zwischen Entwurf und hoher Qualität, und die OCR Die Engine schreibt eine echte Textebene in das Dokument. Die Antwort liefert das fertige Dokument. PDF als Base64 JSONBereit zum Dekodieren und Speichern.

Was dieser Endpunkt bewirkt

Nimmt ein bildbasiertes oder gescanntes Bild auf. PDF und gibt dasselbe Dokument mit erkanntem, auswählbarem Text zurück. qualityType wechselt zwischen einem schnellen Einzeldurchgang (Entwurf, 1 API Aufruf pro Datei) und seitenweise Erkennung (Hoch, 2 API Anrufe pro Seite), während ocrWhenNeeded überspringt pages die bereits durchsuchbar sind. Die Ausgabe erfolgt als Base64 docContent Feld in einem JSON Antwort oder über eine Location Umfrage URL auf 202.

Verwandte Blog-Beiträge
Zu dieser Funktion gibt es noch keinen Blogbeitrag – folgt in Kürze.
Schauen Sie sich in der Zwischenzeit im PDF4me-Blog Tutorials und Arbeitsabläufe für alle Plattformen an.
Besuchen Sie den Blog

Authentifizierung Ihres API Anfrage

Jeder PDF4me REST Der Anruf muss Ihre API Schlüssel im Authorization Header als Basic Auth. Ihren Schlüssel erhalten oder ändern Sie ihn im Entwickler-Dashboard.

Endpunkt

POST/api/v2/ConvertOcrPdf

Wichtige Fakten, die Sie nicht verpassen sollten

Gemischte Feldtypen: Zeichenketten UND boolesche Werte
ocrWhenNeeded Und outputFormat sind die STRINGS "WAHR" / "FALSCH", während isAsync Und mergeAllSheets Sind JSON Boolesche Werte. Dies entspricht den offiziellen Codebeispielen; eine Vermischung ist eine häufige Ursache für 400-Fehler.
Die Antwort lautet: JSON, nicht Rohbytes
Eine Antwort von 200 führt docName plus docContent, das fertige PDF als Base64 Zeichenkette.Dekodieren docContent Vor dem Speichern. Schreiben Sie den Antworttext nicht unverändert auf die Festplatte.
Draft und High werden unterschiedlich abgerechnet
Entwurfskosten 1 API Anruf pro Datei; Hohe Kosten 2 API Anrufe pro Seite und ist der für Scans optimierte Modus. Beibehalten ocrWhenNeeded: "WAHR" also bereits durchsuchbar pages werden übersprungen statt erneut verarbeitet.

HTTP aufstellen

Verfahren: POST
URL: https://api.pdf4me.com/api/v2/ConvertOcrPdf
Inhaltstyp: application/json
Authorization: Basic <Ihre PDF4me API Schlüssel>

Schicken isAsync: WAHR im Körper. 200 Rückgaben JSON mit dem Base64 docContentDie 202 gibt ein zurück Location Überschrift mit einer Umfrage URL; GET Das URL mit dem gleichen Authorization Header bis es 200 mit dem JSON Ergebnis.

Wie erstellt man einen Scan? PDF durchsuchbar?

Ein gescannter PDF sind nur Bilder von pagesNichts ist auswählbar und nichts entspricht einer Textsuche. OCR (optische Zeichenerkennung, siehe Überblick darüber, wie OCR WerkeDas Programm liest jedes Seitenbild und schreibt die erkannten Wörter als echte Textebene in die Datei. Nach der Konvertierung verhält sich das Dokument wie ein digital erstelltes Dokument. PDF: Such-, Kopier- und Bildschirmlesefunktionen funktionieren alle, und es ist bereit für nachfolgende Schritte wie PDF/A Archivierung oder Suchen und Ersetzen.

Draft vs HighEntwurfHoch
Am besten geeignet fürNormal PDFs die meistens eine Textebene habenGescannte oder bildbasierte Dokumente
Kosten1 API Anruf pro Datei2 API Anrufe pro Seite
ErkennungLichtdurchgangVollständiger Wert pro Seite OCR
Kombinieren Sie mitocrWhenNeeded: "true" zum Überspringen der Suchfunktion pageslanguage wenn der Text verstümmelt zurückkommt

API Körperfelder

ParameterErforderlichTypWas es tutBeispiel
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

Beispielnutzlasten

Hoher Modus. Gescanntes Dokument mit OCR

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

Entwurfsmodus. Gemischtes Dokument, Suchfunktion überspringen pages

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

Tipps zur Postboten-Abholung

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-Beispiel

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

Was bedeutet das? API zurückkehren?

JSON, nicht die rohen Dateibytes. Dekodieren Sie die docContent Feld, um das fertige PDFDie

FeldTypWas es enthält
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.

Codebeispiele

Funktionierende End-to-End-Implementierungen, jeweils mit einem gescannten Beispiel. PDF und die genaue Nutzlast von dieser Seite:

Häufig gestellte Fragen

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.

Ähnliche Aktionen

Dieselbe Aufgabe auf anderen Plattformen

Hilfe erhalten