Home >Backend Development >Python Tutorial >python使用reportlab实现图片转换成pdf的方法

python使用reportlab实现图片转换成pdf的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-10 15:11:482116browse

本文实例讲述了python使用reportlab实现图片转换成pdf的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/env python
import os
import sys
from reportlab.lib.pagesizes import A4, landscape
from reportlab.pdfgen import canvas
f = sys.argv[1]
filename = ''.join(f.split('/')[-1:])[:-4]
f_jpg = filename+'.jpg'
print f_jpg
def conpdf(f_jpg):
  f_pdf = filename+'.pdf'
  (w, h) = landscape(A4)
  c = canvas.Canvas(f_pdf, pagesize = landscape(A4))
  c.drawImage(f, 0, 0, w, h)
  c.save()
  print "okkkkkkkk."
conpdf(f_jpg)

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn