python圖片轉換成pdf

#!/usr/bin/env python

import os
import glob
from reportlab.lib.pagesizes import letter, A4, landscape
from reportlab.platypus import SimpleDocTemplate, Image
from reportlab.lib.units import inch
from reportlab.pdfgen import canvas

#filename = 'd:/tux.png'

#get_python_image()

def topdf(filename):
    filename_pdf = filename[:-4] + '.pdf'
    #im = Image(filename)
    #doc = SimpleDocTemplate(filename_pdf, pagesize=landscape(A4))
    #parts = []
    #parts.append(im)
    #doc.build(parts)
    c = canvas.Canvas(filename_pdf, pagesize=landscape(A4))
    (w, h) =landscape(A4)
    width, height = letter
    #c.drawImage(filename, inch, height - 2 * inch) # Who needs consistency?
    c.drawImage(filename, 0, 0, w, h)
    c.showPage()
    c.save()    
    print "end."
    
path = os.path.abspath(os.path.join(os.getcwd(), __file__))
path = os.path.dirname(path)
print path
#topdf('D:\\4.jpg')
filelist = glob.glob(os.path.join(path, '*.jpg'))
for filename in filelist:
    print filename
    topdf(filename)

    
    

你可能感兴趣的:(python圖片轉換成pdf)