Python Reportlab转换jpg为pdf
Python平台的优秀PDF报表类库Reportlab。它不属于Python的标准类库,所以必须手动下载类库包并安装: http://www.reportlab.com/software/opensource/rl-toolkit/download/
根据自己系统和版本选择下载,我就下了个reportlab-2.6.win32-py2.7.exe
因为涉及到把图片转换为PDF,所以还需要Python imaging library(PIL)类库:Python Imaging Library: http://www.pythonware.com/products/pil/
All our software requires Python (versions 2.4 through 2.7 supported; v2.6 is recommended if you're new to Python)
If you want to use GIF or PNG images in your PDFs, you will also need to install the Python Imaging Library.
Canvas的默认大小为A4
#!/usr/bin/env python
#-*-coding:utf-8-*-
import os
import sys
from reportlab.lib.pagesizes import A4, landscape
from reportlab.pdfgen import canvas
filename = '6598223154354374768.jpg'
fileExt = filename[:filename.rindex('.')]
def convertpdf():
f_pdf = fileExt+'.pdf'
(w, h) = landscape(A4)
c = canvas.Canvas(f_pdf, pagesize = landscape(A4))
c.drawImage(filename, 0, 0, w, h)
c.save()
print "convert ok."
convertpdf()
补充:Web开发 , Python ,