[英]png images to one pdf in python
我有一个.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()
但他们俩都将每张照片放在另一张下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.