DEV Community

César Freitas
César Freitas

Posted on

Extract clean text from PDFs in Python with one API call

Extract Clean Text from PDFs in Python with One API Call

Working with PDFs can be a challenge for developers and makers alike. PDFs often contain valuable information that is buried within the digital or scanned images, making it difficult to extract text without significant manual intervention. For instance, extracting data from receipts or invoices requires a lot of time and effort, and even then, the results might not always be accurate.

Document Intelligence API

One solution to this problem is Document Intelligence API by RapidAPI. This API can take any PDF (digital or scanned) as input and return clean, LLM/RAG-ready Markdown text with built-in OCR capabilities. But that's not all - it can also extract invoice/receipt data in JSON format.

The API uses advanced algorithms and machine learning models to automatically detect the layout of the document, remove noise, and recognize text from images. The result is a well-formatted Markdown string that can be easily parsed by LLM/RAG models for further analysis or processing.

Request/Response

When you make an API call using Document Intelligence API, you typically pass in a PDF file or a URL to the document. The response will contain two main parts:

  • Markdown Text: This is the clean text extracted from the PDF, formatted in Markdown syntax.
  • Invoice/Receipt Data (JSON): If the PDF contains relevant data like invoices or receipts, this section will contain the extracted information in JSON format.

The API call might look something like this:

"Send a request with a PDF file to extract its content."

And the response might look like this:

"A JSON object containing invoice details extracted from the PDF."

Call to Action

If you're looking for an easy way to integrate PDF text extraction into your Python project, we recommend trying out Document Intelligence API on RapidAPI. The free tier is available and will give you a good starting point for exploring the API.

Keep in mind that each request comes with a reasonable limit on the number of documents you can process per day. But if you're looking to automate text extraction from PDFs, this API is definitely worth considering.

Before proceeding, make sure to check out RapidAPI's documentation and terms of service to understand how their free tier works and what's included in the paid plans.

Quick example

curl -X POST 'https://document-intelligence3.p.rapidapi.com/v1/pdf-to-markdown' \
  -H 'X-RapidAPI-Key: YOUR_RAPIDAPI_KEY' \
  -H 'X-RapidAPI-Host: document-intelligence3.p.rapidapi.com' \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com/file.pdf"}'
Enter fullscreen mode Exit fullscreen mode

Try it: the Document Intelligence API is live on RapidAPI with a free tier — get your key here.

Top comments (0)