Blog Post

How to Convert Scanned PDF to Text with PSPDFKit's OCR API

Oghenerukevwe Henrietta Kofi
Illustration: How to Convert Scanned PDF to Text with PSPDFKit's OCR API

In this blog post, you’ll learn how to use PSPDFKit API to convert a PDF generated from scanned images into a PDF with searchable text content using optical character recognition (OCR).

To follow along with this tutorial, you’ll need a sample PDF for the conversion. The PDF should ideally consist mostly of scanned images of a physical document. You can use this sample document if you don’t have a document of your own. If you open the sample document in a PDF reader, you’ll notice that you can neither select text nor do a search for any of the text in it.

To learn how to perform OCR using our API, read on.

Step 1 — Create a Free Account

Begin by creating a PSPDFKit API account. With our API, you receive 100 credits with the free plan. Different operations on a document consume different amounts of credits, so the number of PDF documents you can generate may vary.

After creating the account, copy your API key from the dashboard.

Step 2 — Make a Request

Using your API key from the previous step, make a request to the /build endpoint, sending over the document you want to process:

curl -X POST https://api.pspdfkit.com/build \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -o result.pdf \
  --fail \
  -F scanned=@document.pdf \
  -F instructions='{
      "parts": [
        {
          "file": "scanned"
        }
      ],
      "actions": [
        {
          "type": "ocr",
          "language": "english"
        }
      ]
    }'

Open and inspect the result.pdf file; you’ll now be able to highlight and search for text within the document.

Summary

PSPDFKit’s OCR API is capable of supporting both basic and advanced OCR use cases. Using PSPDFKit’s OCR API, you can:

  • Convert a scanned PDF or image into a searchable PDF.

  • Convert many scanned documents and merge them into one searchable PDF.

  • Perform OCR for documents in any of the supported languages, including English, Italian, and Turkish.

For more information, you can view the complete documentation for the OCR API.

Author
Oghenerukevwe Henrietta Kofi Server and Services Engineer

Rukky joined PSPDFKit as an intern in 2022 and is currently a software engineer on the Server and Services Team. She’s passionate about building great software, and in her spare time, she enjoys reading cheesy novels, watching films, and playing video games.

Related Products
PSPDFKit API

Product Page
Guides

Share Post
Free 60-Day Trial Try PSPDFKit in your app today.
Free Trial

Related Articles

Explore more
TUTORIALS  |  API • Python • How To

How to Convert DOCX to WebP Using Python

TUTORIALS  |  API • OCR • How To

How to OCR PDFs with PSPDFKit API

TUTORIALS  |  Python • API • OCR

Extract Text from PDF in Python: A Comprehensive Guide Using PyPDF and PSPDFKit API