从图像列表创建 PDF [英] Create PDF from a list of images

查看:23
本文介绍了从图像列表创建 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何实用的方法可以使用 Python 从图像文件列表中创建 PDF?

Is there any practical way to create a PDF from a list of images files, using Python?

在 Perl 中,我知道那个模块.有了它,我只需 3 行就可以创建一个 PDF:

In Perl I know that module. With it I can create a PDF in just 3 lines:

use PDF::FromImage;
...
my $pdf = PDF::FromImage->new;
$pdf->load_images(@allPagesDir);
$pdf->write_file($bookName . '.pdf');

我需要做一些与此非常相似的事情,但是在 Python 中.我知道 pyPdf 模块,但我想要一些简单的东西.

I need to do something very similar to this, but in Python. I know the pyPdf module, but I would like something simple.

推荐答案

安装 FPDF for Python:

pip install fpdf

现在您可以使用相同的逻辑:

Now you can use the same logic:

from fpdf import FPDF
pdf = FPDF()
# imagelist is the list with all image filenames
for image in imagelist:
    pdf.add_page()
    pdf.image(image,x,y,w,h)
pdf.output("yourfile.pdf", "F")

您可以在教程页面官方文档.

这篇关于从图像列表创建 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆