Open In App

How to convert PDF file to Excel file using Python?

In this article, we will see how to convert a PDF to Excel or CSV File Using Python. It can be done with various methods, here are we are going to use some methods.

Method 1: Using pdftables_api 



Here will use the pdftables_api Module for converting the PDF file into any other format. It’s a simple web-based API, so can be called from any programming language.

Installation:



pip install git+https://github.com/pdftables/python-pdftables-api.git

After Installation, you need an API KEY. Go to PDFTables.com and signup, then visit the API Page to see your API KEY.

For Converting PDF File Into excel File we will use xml() method.

Syntax:

xml(pdf_path, xml_path)

Below is the Implementation:

PDF File Used:

PDF FILE




# Import Module
import pdftables_api
  
# API KEY VERIFICATION
conversion = pdftables_api.Client('API KEY')
  
# PDf to Excel 
# (Hello.pdf, Hello)
conversion.xlsx("pdf_file_path", "output_file_path")

Output:

EXCEL FILE

Method 2: Using tabula-py

Here will use the tabula-py Module for converting the PDF file into any other format.

Installation:

pip install tabula-py

Before we start, first we need to install java and add a java installation folder to the PATH variable.

Approach:

Syntax:

read_pdf(PDF File Path, pages = Number of pages, **agrs)

Below is the Implementation:

PDF File Used:

PDF FILE




# Import Module 
import tabula
  
# Read PDF File
# this contain a list
df = tabula.read_pdf("PDF File Path", pages = 1)[0]
  
# Convert into Excel File
df.to_excel('Excel File Path')

Output:

EXCEL FILE


Article Tags :