我有一个 .png 图片列表。我需要将它们全部转换成一个pdf,每页9张图像,但不是将它们一个接一个地垂直放置,而是填充所有宽度,然后才继续下一行。 每次的图片数量可以不同(12,... 15)
我试过fpdf
from fpdf import FPDF
list_of_images = [1.png, 2.png, ... 15.png]
w = 70
h = 60
pdf = FPDF(orientation = 'L')
for image in list_of_images:
pdf.image(image, w=sizew, h=sizeh)
pdf.output("Memory_usage.pdf", "F")
还有 wkhtmltopdf
template = Template('''<!doctype html>
<html>
<body>
<div style="display: flex; flex-direction: row">
{% for image in images %}
<img src="{{ image }}" />
{% endfor %}
</div>
</body>
</html>''')
list_of_images = [1.png, 2.png, ... 15.png]
html = template.render(images=list_of_pict)
with open("my_new_file.html", "wb") as fh:
fh.write(html)
p = subprocess.Popen(['wkhtmltopdf', '-', 'Memory_usage.pdf'], stdin=subprocess.PIPE, universal_newlines=True)
p.communicate(html)
p.wait()
但是他们都把每张图片都放在了另一张下面
最佳答案
关于python - 在python中将png图像转换为一个pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40906463/