New: PDF to E-Invoice for Factur-X/ZUGFeRD, and PDF to PDF/A for archive-ready PDF/A-3b.

Extract Text from PDF Invoice in Python using PDF.co Web API

Extract the text of a PDF invoice using Python and PDF.co’s PDF-to-Text API. The output is a text file; it does not automatically separate vendor details, invoice numbers, totals or line items into structured fields.

Use this example when you need invoice text for searching or a later processing step. Check important extracted values against the source PDF before using them in another system.

Sample PDF
Sample PDF
Output Text
Output Text

Step 1: Download Files

We highly recommend that you copy or download the Python code and the sample PDF so you can follow along.

Step 2: Install Requests Module

We will use the requests module in this sample Python program. You can install it in your machine by running this in the command line (cmd.exe) python -m pip install requests.

Install Requests Module

Step 3: Add API Key

Let’s open the Python code and add our PDF.co API Key in line 6. You can get your API key in your PDF.co dashboard.

Add PDF.co API Key

Step 4: Add Source File

In line 12, add your source PDF file path. You can add your desired output filename in line 18. You can learn more about PDF to Text Web API endpoints at our API Documentation.

Add Source File Path

Step 5: Run Program

Let’s now run our program and view the result in the folder.

Output Inside Folder

This example converts a PDF invoice into text and saves the result. Field extraction, validation and spreadsheet mapping are separate steps. Review amounts, dates and identifiers against the original PDF, particularly when OCR is used.

Related Tutorials

See Related Tutorials