Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách chuyển đổi file PDF sang Excel dùng Python

Python có thư viện lớn xử lý các thao tác. Bài này chuyển PDF sang Excel. Có gói chuyển PDF sang CSV nhưng dùng Tabula-py. Phần lớn tabula-py viết Java đọc PDF chuyển DataFrame Python thành JSON.

Để dùng tabula-py, cần Java cài sẵn. Chuyển PDF sang CSV:

  • Cài gói: pip install tabula-py.
  • Đọc file read_pdf("file location", pages=number) trả DataFrame.
  • Chuyển DataFrame sang Excel: tabula.convert_into('pdf-filename', 'name_this_file.csv',output_format="csv", pages="all") xuất PDF ra Excel.

Ví dụ

Dùng IPL Match Schedule Document chuyển sang Excel.

# Import required Module
import tabula
# Read a PDF File
df = tabula.read_pdf("IPLmatch.pdf", pages='all')[0]
# convert PDF into CSV
tabula.convert_into("IPLmatch.pdf", "iplmatch.csv", output_format="csv", pages='all')
print(df)

Kết quả

Chạy mã chuyển PDF thành file Excel (CSV).

Cách chuyển đổi file PDF sang Excel dùng Python