Lewati ke konten utama

Mengubah PDF menjadi Dapat Diedit PDF Menggunakan OCR

PDF4me Mengubah PDF menjadi Dapat Diedit PDF menggunakan OCR adalah sebuah REST titik akhir yang dipindai PDFs Dapat dicari dan diedit. POST A Base64 PDF ke /api/v2/ConvertOcrPdf, pilih Draf atau Kualitas Tinggi, dan OCR Mesin tersebut menulis lapisan teks sungguhan ke dalam dokumen. Respons yang dikembalikan adalah hasil akhir. PDF sebagai Base64 JSON, siap untuk didekode dan disimpan.

Fungsi dari endpoint ini

Mengambil gambar atau hasil pemindaian PDF dan mengembalikan dokumen yang sama dengan teks yang dikenali dan dapat dipilih. qualityType peralihan antara lintasan tunggal cepat (Draf, 1 API panggilan per file) dan pengenalan per halaman (Tinggi, 2 API panggilan per halaman), sementara ocrWhenNeeded melompati pages yang sudah dapat dicari. Outputnya berupa Base64 docContent lapangan di dalam JSON tanggapan, atau melalui Location jajak pendapat URL pada 202.

Postingan Blog Terkait
Belum ada postingan blog untuk fitur ini — akan segera hadir.
Sementara itu, jelajahi blog PDF4me untuk menemukan tutorial dan alur kerja di berbagai platform.
Kunjungi blog ini

Memverifikasi Identitas Anda API Meminta

Setiap PDF4me REST panggilan harus menyertakan Anda API kunci di Authorization Header sebagai otentikasi Dasar. Dapatkan atau putar kunci Anda dari dasbor pengembang.

Titik akhir

POST/api/v2/KonversiOcrPdf

Fakta Penting yang Tidak Boleh Anda Lewatkan

Tipe bidang campuran: string DAN boolean
ocrWhenNeeded Dan outputFormat adalah SENAR "BENAR" / "PALSU", ketika isAsync Dan mergeAllSheets adalah JSON boolean. Ini mencerminkan contoh kode resmi; mencampuradukkan keduanya adalah penyebab umum kesalahan 400.
Jawabannya adalah JSON, bukan byte mentah
Respons 200 membawa docName ditambah docContent, selesai PDF sebagai Base64 string. Dekode docContent Sebelum menyimpan. Jangan menulis isi respons ke disk apa adanya.
Draft dan High ditagih secara berbeda.
Draf biaya 1 API panggilan per berkas; Biaya tinggi 2 API panggilan per halaman dan merupakan mode yang dirancang untuk pemindaian. Simpan ocrWhenNeeded: "BENAR" jadi sudah bisa dicari pages dilewati alih-alih diproses ulang.

HTTP pengaturan

Metode: POST
URL: https://api.pdf4me.com/api/v2/ConvertOcrPdf
Tipe Konten: aplikasi/json
Authorization: Dasar <Anda PDF4me API kunci>

Mengirim isAsync: BENAR di dalam tubuh. 200 pengembalian JSON dengan Base64 docContent. 202 mengembalikan Location header dengan jajak pendapat URL; GET itu URL dengan yang sama Authorization header hingga mengembalikan kode 200 dengan JSON hasil.

Bagaimana cara membuat hasil pindaian? PDF dapat dicari?

Sebuah hasil pemindaian PDF hanya gambar-gambar pagesTidak ada yang bisa dipilih dan tidak ada yang cocok dengan pencarian teks. OCR (pengenalan karakter optik, lihat gambaran umum tentang bagaimana OCR karya(Program ini membaca setiap gambar halaman dan menulis kata-kata yang dikenali ke dalam file sebagai lapisan teks sungguhan. Setelah konversi, dokumen tersebut berperilaku seperti dokumen digital asli.) PDFFungsi pencarian, penyalinan, dan pembaca layar semuanya berfungsi, dan siap untuk langkah-langkah selanjutnya seperti: PDF/A pengarsipan atau cari dan ganti.

Draft vs TinggiDrafTinggi
Terbaik untukNormal PDFs yang sebagian besar memiliki lapisan teksDokumen hasil pemindaian atau berbasis gambar
Biaya1 API panggilan per berkas2 API panggilan per halaman
PengakuanCahaya melewatiInformasi lengkap per halaman OCR
Padukan denganocrWhenNeeded: "true" untuk melewati yang dapat dicari pageslanguage ketika teks yang diterima tidak jelas

API bidang tubuh

ParameterDiperlukanJenisApa fungsinya?Contoh
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

Contoh muatan

Mode tinggi. dokumen yang dipindai dengan OCR

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

Mode draf. Dokumen campuran, lewati pencarian. pages

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

Tips pengambilan oleh tukang pos

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.

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

Apa yang dimaksud dengan API kembali?

JSON, bukan byte file mentah. Dekode docContent lapangan untuk mendapatkan hasil akhir PDF.

BidangJenisIsi di dalamnya
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.

Contoh kode

Mengerjakan implementasi ujung-ke-ujung, masing-masing dengan contoh yang dipindai. PDF dan muatan persis dari halaman ini:

Pertanyaan yang Sering Diajukan (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.

Tindakan terkait

Tugas yang sama di platform lain

Dapatkan Bantuan