im = ImageReader('00001.png')c = canvas.Canvas('networkanalyze.pdf',pagesize=A4)c.drawImage(im,10,mask='auto')c.showPage()c.save()
追溯:
Traceback (most recent call last): file "pdf.py",line 9,in <module> c.drawImage(im,mask='auto') file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/pdfgen/canvas.py",line 909,in drawImage rawdata = image.getRGBData() file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/lib/utils.py",line 656,in getRGBData annotateException('\nIDentity=%s'%self.IDentity()) file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/lib/utils.py",line 653,in getRGBData self._data = im.tostring() file "/usr/lib/python2.6/site-packages/Pillow-3.2.0-py2.6-linux-x86_64.egg/PIL/Image.py",line 699,in tostring "Please call tobytes() instead.")Exception: tostring() has been removed. Please call tobytes() instead.
第二种方法:
def generate_pdf(c): """ letter :- (612.0,792.0) """ im = Image.open("00001.png") c.drawInlineImage(im,256,720,wIDth=100,height=60)c = canvas.Canvas("report_image.pdf",pagesize=letter)generate_pdf(c)c.save()
追溯:
Traceback (most recent call last): file "pdf2.py",line 14,in <module> generate_pdf(c) file "pdf2.py",line 11,in generate_pdf c.drawInlineImage(im,height=60) file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/pdfgen/canvas.py",line 837,in drawInlineImage img_obj = pdfImage(image,x,y,wIDth,height) file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/pdfgen/pdfimages.py",line 42,in __init__ self.getimageData() file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/pdfgen/pdfimages.py",line 156,in getimageData imagedata,imgwIDth,imgheight = self.PIL_imagedata() file "/usr/lib/python2.6/site-packages/reportlab-2.7-py2.6-linux-x86_64.egg/reportlab/pdfgen/pdfimages.py",line 117,in PIL_imagedata raw = myimage.tostring() file "/usr/lib/python2.6/site-packages/Pillow-3.2.0-py2.6-linux-x86_64.egg/PIL/Image.py",in tostring "Please call tobytes() instead.")Exception: tostring() has been removed. Please call tobytes() instead.
所以它似乎与代码无关.
我在服务器上运行python:
Python 2.6.6(r266:84292,2013年11月21日,10:50:32)
linux2上的[GCC 4.4.7 20120313(Red Hat 4.4.7-4)]
枕头版:Pillow-3.2.0-py2.6-linux-x86_64.egg
reportlab的版本:reportlab-2.7-py2.6-linux-x86_64.egg
我没有成功搜索这个特殊的错误,
我该怎么做才能解决这个问题?
因此,如果将Pillow降级到3.1版,您的代码可能会有效.
但是,您的版本的reportlab已经过时,因为您的版本为2.7并且version 3.3已发布.我没试过,但我想他们已经解决了这个问题,至少,值得一试!
reportlab的最新版本与Python 2.6不兼容,但你应该至少升级到Python 2.7,甚至升级到Python 3 总结
以上是内存溢出为你收集整理的python – reportlab图像到PDF:“请致电tobytes()”全部内容,希望文章能够帮你解决python – reportlab图像到PDF:“请致电tobytes()”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)