Reputation: 102
The souce file is here.The fetch code is sify
.It's just one jpg. If you can't download it, please contact [email protected].
However this image doesn't work with fpdf
package, I don't know why. You can try it.
Thus I have to use the img2pdf
. With the following code I converted this image to pdf successfully.
t=os.listdir()
with open('bb.pdf','wb') as f:
f.write(img2pdf.convert(t))
However, when multiple images are combined into one pdf file, the img2pdf
just combine each image by head_to_tail. This causes every pagesize = imgaesize. Briefly, the first page of pdf is 30 cm*40 cm while the second is 20 cm*10 cm the third is 15*13...That's ugly.
I want the same pagesize(A4
for example) and the same imgsize in every page of the pdf. One page of pdf with one image.
Upvotes: 1
Views: 3430
Reputation: 3363
Glancing at the documentation for img2pdf, it allows you to set the paper size by including layout details to the convert call:
import img2pdf
letter = (img2pdf.in_to_pt(8.5), img2pdf.in_to_pt(11))
layout = img2pdf.get_layout_fun(letter)
with open('test.pdf', 'wb') as f:
f.write(img2pdf.convert(['image1.jpg','image2.jpg'], layout_fun=layout))
Upvotes: 2