使用PDFminer:Python从发票PDF中提取特定数据值

2024-10-05 11:37:00 发布

您现在位置:Python中文网/ 问答频道 /正文

希望仅从具有不同结构的多个PDF中提取特定数据

我已将所有pdf文件存储到发票文件夹中。 我尝试使用pdfminer库从pdf中提取数据

def extract_text(pdf_path):
    text21 = ''
    for page in extract_text_by_page(pdf_path):
        text21 = text21 + str(page[:-1]) + ' '
    return text21


inv = glob.glob(path+"/Invoice/*.pdf")

for i in inv:
    print(i)
    page = extract_text(i)
    print(page)
    data1 = str(page)
    lan = len(data1)

     x = re.search("Invoice Number:", page)
    x1 = re.search("Invoice No:", page)
    x2 = re.search("Bill No:" , page)
    x3 = re.search("Bill:" , page)
    if (x or x1 or x2 or x3):
        if x:
            yo = x.end()
        elif x1:
            yo = x1.end()
        elif x2:
            yo = x2.end()
        elif x3:
            yo = x3.end()

类似地,希望从发票PDF文件中附加发票日期、账单总金额。如何将所有值作为提取的值附加到单独的变量中,以供其他进程使用


Tags: pathtextresearchpdfpageextract发票
1条回答
网友
1楼 · 发布于 2024-10-05 11:37:00

使用pText

with open("input.pdf", "rb") as pdf_file_handle:
    l = RegularExpressionTextExtraction("Invoice Number :[0-9]+")
    doc = PDF.loads(pdf_file_handle, [l])

# do something with these events
l.get_matched_text_render_info_events_per_page(0)

相关问题 更多 >

    热门问题