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 a free account, you can process up to 100 documents each month using the API.

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.

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 • Tesseract • OCR

How to Use Tesseract OCR in Python

PRODUCTS  |  API • Releases • Components

PSPDFKit API OCR and Office Conversion Improvements

DEVELOPMENT  |  API • Elixir • Insights

Rate Limiting Server Requests in Elixir