python 图片转pdf,在python中将png图像转换为一个pdf

I have a list of .png images. I need to convert all of them into one pdf, 9 images per page , but not to place them one after another vertically, but fill in all the width, and only then continue to next row.

Amount of pictures can be different each time (12, ... 15)

I have tried 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")

and also wkhtmltopdf

template = Template('''

{% for image in images %}

%7B%7B%20image%20%7D%7D

{% endfor %}

''')

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()

but both of them place each picture one under another

解决方案

Just place each image at required coordinates using FPDF:

pdf.image(image, x=50, y=100, w=sizew, h=sizeh)

More info on FPDF documentation: image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值