python 图片转pdf

def img2pdf(img_files, name):
    doc = fitz.open()
    for file in img_files:
        page = doc.new_page()
        img_doc = fitz.open(file)
        pdf_bytes = img_doc.convert_to_pdf()
        img_pdf = fitz.open("pdf", pdf_bytes)
        img_rect = img_pdf.page_cropbox(0)
        #调整大小
        page.set_mediabox(fitz.Rect(0, 0, 1000, img_rect.y1 / img_rect.x1 * 1000))
        r = fitz.Rect(0, 0, page.rect.width, page.rect.height)
        page.show_pdf_page(r, img_pdf, 0, rotate=0)
    doc.save(name)
    doc.close()

python 图片转pdf

上一篇:opencv4nodejs linux centos 安装 install


下一篇:Java自学第六章:创建第一个Java项目