pdfplumber and pypdf return '' for a scanned page: it holds 1 image and 0 characters, and neither library runs OCR. parserkit reads it and checks the totals for $0.02 a page, 50 pages free.
extract_text returns an empty string on a scanned PDF
Your script got '' because the page is a single image with 0 characters behind it, and pdfplumber 0.11.10 and pypdf 7.0.0 have no OCR step. Bolting on OCR adds text plus misread digits that nothing checks. parserkit reads the scan and checks every total: 13 of 13 passed on this invoice.
Error fixesUpdated
$ python extract_text.py invoice-veldhuis-v-scan.pdf
pdfplumber: ''
pypdf: ''Causes
Why it happens and the fix for each
The page is a picture of text
extract_textreturns''because the page holds one scanned image and no character objects. You can check withis_scan.py, which printedpage 1: 0 characters, 1 imagesoninvoice-veldhuis-v-scan.pdf, or from the shell withpdffonts(no fonts listed) andpdfimages -list(1 image). Oninvoice-veldhuis-v-digital.pdf, the same invoice with a text layer,is_scan.pyprintedpage 1: 860 characters, 0 imagesandpdffontslisted 2 fonts,LiberationSans-BoldandLiberationSans. Add a text layer with OCR before callingextract_text, or skip that step and send the file to the invoice parser API, which reads scans and checks the totals.is_scan.py on both copies $ python is_scan.py invoice-veldhuis-v-scan.pdf page 1: 0 characters, 1 images $ python is_scan.py invoice-veldhuis-v-digital.pdf page 1: 860 characters, 0 imagesNeither library does OCR
Both pdfplumber 0.11.10 and pypdf 7.0.0 only read characters already stored in the PDF. The pdfplumber README notes that it "Works best on machine-generated, rather than scanned, PDFs." and lists optical character recognition (OCR) among the things pdfplumber does not provide, while the pypdf docs state that "pypdf is not OCR software." and "If a PDF page appears to contain only an image (e.g., a scanned document), the extracted text may be minimal or visually empty." If your script hits a scan, run
ocrmypdfwith Ghostscript and Tesseract OCR installed first, or callPOST /v1/parseand get checked fields back with nothing to install. (The same thing happens with table extractors like Tabula and Camelot.)You test for None, but you get an empty string
A check like
if text is None:misses scanned pages because both libraries return an empty string instead. In our run oninvoice-veldhuis-v-scan.pdf,extract_text.pyprintedpdfplumber: ''andpypdf: '', notNone. Checkif not text or not text.strip():or check the character and image counts on each page before you parse.OCR adds text, and its own misreads
As the OCRmyPDF README puts it, "OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched or copy-pasted." After we ran
ocrmypdf17.13.0 with Tesseract 5.5.0 on the scan,pdffontslisted 1 font,NotoSans, and pdfplumber read the page, but with OCR misreads: it returned"Fabric cable 3 m, ochre 15 11525 168,75"for a unit price of 11,25, and"VAT NLO04192837B01", putting a letter O in the buyer's VAT numberNL004192837B01. Catching them means checking every line total and VAT number yourself;POST /v1/parseruns those checks on the extracted fields for you.pdfplumber after ocrmypdf, 2 of its lines VAT NLO04192837B01 Fabric cable 3 m, ochre 15 11525 168,75
Example
The same scanned invoice through the parse API
invoice-veldhuis-v-scan.pdf is the scan both libraries returned '' for: a Dutch invoice in euros with VAT and a deposit. With the invoice preset it came back verified, with the VAT numbers and the IBAN checked too.
POSTapi.parserkit.com/v1/parse?wait=60
curl "https://api.parserkit.com/v1/parse?wait=60" \
-H "Authorization: Bearer $PARSERKIT_API_KEY" \
-F file=@invoice-veldhuis-v-scan.pdf \
-F preset=invoiceimport os
import requests
with open("invoice-veldhuis-v-scan.pdf", "rb") as file:
res = requests.post(
"https://api.parserkit.com/v1/parse",
params={"wait": 60},
headers={"Authorization": f"Bearer {os.environ['PARSERKIT_API_KEY']}"},
files={"file": file},
data={"preset": "invoice"},
)
job = res.json()
print(job["verification_status"], job["data"]["invoice_number"], job["data"]["amount_due"])import { openAsBlob } from "node:fs";
const form = new FormData();
form.append("file", await openAsBlob("invoice-veldhuis-v-scan.pdf"), "invoice-veldhuis-v-scan.pdf");
form.append("preset", "invoice");
const res = await fetch("https://api.parserkit.com/v1/parse?wait=60", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.PARSERKIT_API_KEY}` },
body: form,
});
const job = await res.json();
console.log(job.verification_status, job.data.invoice_number, job.data.amount_due);{
"id": "job_w5pmsfb7zsntwoj6qe3c",
"status": "succeeded",
"pages": 1,
"digital_pages": 0,
"ocr_pages": 1,
"cost_usd": 0.02,
"verification_status": "verified",
"duplicate": null,
"data": {
"invoice_number": "2026-0503",
"issue_date": "2026-11-03",
"due_date": "2026-11-17",
"currency": "EUR",
"vendor": {
"name": "Veldhuis Lichtwerk B.V.",
"vat_id": "NL859312406B01"
},
"customer": {
"name": "Kanaalhuis Hotels B.V.",
"vat_id": "NL004192837B01"
},
"line_items": [
{
"description": "Pendant lamp Lune 40, brass",
"quantity": 4,
"unit_price": 189,
"total": 756
},
{
"description": "Wall light Kade, matte black",
"quantity": 10,
"unit_price": 74.5,
"total": 745
}
],
"subtotal": 2331.75,
"tax_total": 489.67,
"grand_total": 2821.42,
"amount_paid": 750,
"amount_due": 2071.42,
"payment": {
"iban": "NL29STRD0417238562",
"bic": "STRDNL2U"
}
},
"verification": {
"status": "verified",
"math_balanced": true,
"coverage": {
"values": 46,
"checked": 46
},
"checks": [
{
"kind": "line_total",
"path": "line_items[0].total",
"status": "pass",
"expected": 756,
"actual": 756,
"difference": 0,
"message": "quantity x unit price"
},
{
"kind": "line_total",
"path": "line_items[1].total",
"status": "pass",
"expected": 745,
"actual": 745,
"difference": 0,
"message": "quantity x unit price"
},
{
"kind": "sum",
"path": "subtotal",
"status": "pass",
"expected": 2331.75,
"actual": 2331.75,
"difference": 0,
"message": "the line totals"
},
{
"kind": "sum",
"path": "grand_total",
"status": "pass",
"expected": 2821.42,
"actual": 2821.42,
"difference": 0,
"message": "the line totals + tax"
},
{
"kind": "balance",
"path": "amount_due",
"status": "pass",
"expected": 2071.42,
"actual": 2071.42,
"difference": 0,
"message": "grand total less the amount paid"
},
{
"kind": "eu_vat",
"path": "vendor.vat_id",
"status": "pass",
"expected": null,
"actual": "NL859312406B01",
"difference": null,
"message": "a well-formed EU VAT number"
},
{
"kind": "eu_vat",
"path": "customer.vat_id",
"status": "pass",
"expected": null,
"actual": "NL004192837B01",
"difference": null,
"message": "a well-formed EU VAT number"
},
{
"kind": "iban",
"path": "payment.iban",
"status": "pass",
"expected": null,
"actual": "NL29STRD0417238562",
"difference": null,
"message": "a well-formed IBAN"
}
]
}
}Real response from . Trimmed to the first two line items and eight of the 13 checks, with addresses, bounding boxes, empty fields and file links left out.
Four routes through the same scanned invoice
What each route gave back on the scan.
| Route | Text from the scan | Fields | Checked |
|---|---|---|---|
| parserkit, invoice preset | Read by OCR | Invoice fields and 5 line items | Verified, every check passed, $0.02 |
| pdfplumber 0.11.10 | '' (empty string) | No | No |
| pypdf 7.0.0 | '' (empty string) | No | No |
| ocrmypdf 17.13.0, then pdfplumber | Full text, with 11525 for 11,25 and a letter O in a VAT number | No, plain lines | No |
Source: Reproduction log
Check every page for a text layer
Before you trust extract_text, check what is on the page. In our run, is_scan.py printed page 1: 0 characters, 1 images on invoice-veldhuis-v-scan.pdf, and page 1: 860 characters, 0 images on invoice-veldhuis-v-digital.pdf. With the text layer present, either library returned the page text.
You can check the same thing from the command line without writing Python. On the scan, pdffonts printed no fonts and pdfimages -list showed 1 image, the scanned page, whereas on the text copy pdffonts listed 2 fonts, LiberationSans-Bold and LiberationSans.
import sys
import pdfplumber
with pdfplumber.open(sys.argv[1]) as pdf:
for number, page in enumerate(pdf.pages, start=1):
print(f"page {number}: {len(page.chars)} characters, {len(page.images)} images")What parserkit does with the scan
When you send a PDF to our PDF to JSON API at POST /v1/parse, pages with a text layer are read from it and pages without one go through OCR, and the job counts them in digital_pages and ocr_pages. In our first run on invoice-veldhuis-v-scan.pdf with the invoice preset, 1 page was read by OCR and the job finished with status succeeded and verified, all 13 checks passing: 5 line items, EUR with 21% VAT and a 750,00 deposit, and it read the buyer's VAT number as NL004192837B01 and passed the EU VAT and IBAN checks.
A 1-page invoice like this costs $0.02, and the rate drops to $0.01 a page past 5,000 pages in a UTC month. Failed jobs and exact duplicates cost nothing, and you get $1 in free credit (50 pages, no card) on Google sign-in; see the pricing page.
FAQ
Common questions
Why does pdfplumber extract_text return an empty string?
pdfplumber does not do OCR, so when a page is a scanned image with 0 characters in the PDF, there is no text for it to read. On invoice-veldhuis-v-scan.pdf, pdfplumber 0.11.10 returned ''. parserkit read the same scan with OCR and returned it verified, 13 of 13 checks passing, for $0.02.
Why does pypdf extract_text return nothing?
As the pypdf docs say, "pypdf is not OCR software." When a page only holds an image, pypdf 7.0.0 has no character objects to extract and returns ''. parserkit runs OCR on pages like that and checks the totals it reads, at $0.02 a page.
Does extract_text return None or an empty string?
On a page with no text layer, pdfplumber and pypdf both return an empty string '', not None. Test for an empty string or check the page's character count rather than testing only for None. parserkit skips the test: it reads text pages and scans alike and counts them in digital_pages and ocr_pages.
How do I get text out of a scanned PDF in Python?
ocrmypdf (which needs Ghostscript and Tesseract OCR installed) adds a text layer that pdfplumber or pypdf can read, but in our test Tesseract misread an 11,25 unit price as 11525 and NL004192837B01 as NLO04192837B01, and nothing flagged either. parserkit's POST /v1/parse runs OCR on pages without a text layer, checks line totals and VAT numbers, and returned this scan verified for $0.02.
What does parserkit cost for a scan like this?
Failed jobs and exact duplicates cost nothing, and the rate drops to $0.01 a page past 5,000 pages in a UTC month. parserkit charges $0.02 a page and gives you $1 in free credit on Google sign-in, 50 pages with no card.
Related
- tabula read_pdf returns []tabula-py gives an empty list on scans and JavaNotFoundError without Java. Both reproduced, the fix for each, and parserkit reading the scan.
- camelot read_pdf finds no tablesWhy Camelot returns TableList n=0 on scans and borderless tables, the fix for each, and how parserkit reads the scan in one call.
- PDF to JSON APIYour own JSON Schema in, those fields out, with sums re-added.
- Invoice parser APILine items, taxes and totals as JSON, with every sum re-added.
- Free document OCR APIsparserkit first for free invoice and receipt OCR, 50 pages with no card, then Azure, AWS Textract and Google Document AI.
- PDF to JSON converterTurn the tables in a PDF into JSON rows with typed columns and the page of every row, free without an account.
- PDF to Excel converterPull the tables out of a PDF, digital or scanned, into Excel with the printed column names, free and without an account.
- Why can't I copy text from a PDF?Why a PDF won't let you copy, and how parserkit's free tools read scans straight into Excel, CSV and JSON.
Start free
Send us your worst scan
Your first $1 is free: 50 pages with every check and export, no card.
