python - Create PDF from a list of images -


is there practical way create pdf list of images files, using python?

in perl know that module. can create pdf in 3 lines:

use pdf::fromimage; ... $pdf = pdf::fromimage->new; $pdf->load_images(@allpagesdir); $pdf->write_file($bookname . '.pdf'); 

i need similar this, in python. know pypdf module, simple.

@edit

if came through google, here's code:

from fpdf import fpdf pil import image def makepdf(pdffilename, listpages, dir = ''):     if (dir):         dir += "/"      cover = image.open(dir + str(listpages[0]) + ".jpg")     width, height = cover.size      pdf = fpdf(unit = "pt", format = [width, height])      page in listpages:         pdf.add_page()         pdf.image(dir + str(page) + ".jpg", 0, 0)      pdf.output(dir + pdffilename + ".pdf", "f") 

install fpdf python:

pip install fpdf 

now can use same logic:

from fpdf import fpdf pdf = fpdf() # imagelist list image filenames image in imagelist:     pdf.add_page()     pdf.image(image,x,y,w,h) pdf.output("yourfile.pdf", "f") 

you can find more info at tutorial page or official documentation.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -