美文网首页
PDF文档合并-报销单批量粘贴电子发票

PDF文档合并-报销单批量粘贴电子发票

作者: 洗洗睡吧i | 来源:发表于2022-03-18 23:38 被阅读0次

用 pymupdf 将电子发票转成图片,再插入报销单中

# %%
import os
import fitz
from pprint import pprint

fapiao_dir = 'src/'

zhantiedan = 'zhantiedan_blank.pdf'
ztd_pdf = fitz.open(zhantiedan)

new_name = 'fapiao_dayin.pdf'
new_pdf = fitz.open()


def fapiao_zhantie(fapiao=''):
    
    print(f'\n=== fapiao pdf file:\n    {fapiao}')
    src_pdf = fitz.open(fapiao)

    for p, page in enumerate(src_pdf):
        pixmap = page.get_pixmap(dpi=300)
        pixmap.save(f'{fapiao}_{str(p)}.png')
        
        new_pdf.insert_pdf(ztd_pdf)
        end_page = new_pdf[-1]
        end_page.insert_image((100, 100, 700, 500), pixmap=pixmap)

    src_pdf.close()

    new_pdf.save(new_name)
    print(f'    {fapiao} :\n*** Done! ***\n')


for dir, folders, files in os.walk(fapiao_dir):
    for file in files:
        path = os.path.join(dir, file)
        print(path)
        if path[-4:] == '.pdf':
            fapiao_zhantie(path)

ztd_pdf.close()
new_pdf.close()


相关文章

网友评论

      本文标题:PDF文档合并-报销单批量粘贴电子发票

      本文链接:https://www.haomeiwen.com/subject/czzydrtx.html