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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -