簡體   English   中英

使用 python 將 pdf 文件轉換為 excel 與表中的圖像

[英]converting pdf file to excel with images in the table using python

我需要轉換的 pdf 文件將在表格中包含圖像。 我想將 pdf 表格中的文本和圖像轉換為 excel。 請為我推薦合適的庫。

您需要編寫一個腳本來讀取和檢測字符和 excel 單元格。 你可以用 open-cv 和內置的字符識別工具來做到這一點,但我不知道它有多容易。 我能想到的另一種方法是制作一個 ML model,它將從圖像中識別 excel 表。 不過這真的很難,需要很多經驗。

您可以使用PikePDF從 pdf 中提取圖像:

from pikepdf import Pdf, PdfImage

filename = "sample.pdf"
example = Pdf.open(filename)

for i, page in enumerate(example.pages):
    for j, (name, raw_image) in enumerate(page.images.items()):
        image = PdfImage(raw_image)
        out = image.extract_to(fileprefix=f"{filename}-page{i:03}-img{j:03}")

提取圖像后,您可以使用OCR將圖像轉換為表格

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM