0

“IOError:解码器 zip 不可用”当我尝试使用图像渲染 pdf 时出现此类错误。我搜索答案如何解决它,但我发现仅适用于 linux 的决定(但我使用 Windows)。它怎么能修复?

这里有一些python代码:

  result = StringIO()            
            pdf = pisa.pisaDocument(StringIO(html.encode("UTF-8")), result, encoding="utf-8")
            filename = '%s_%s.pdf' % (name.capitalize(), datetime.datetime.now().strftime('%d-%m-%Y'))
            return Response(result.getvalue(), content_type='application/pdf',content_disposition='attachment; filename="%s"' % filename)

我尝试渲染base64,这里是mako的代码:

<div><img src="data:image/png;base64,${img['actions'][0]['data']}"></div>

完整追溯:

    URL: http://localhost:5000/en/case/report/84f3f17c-4cb3-4269-a369-910ddbba1ba4/pdf
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\weberror-0.10.3-py2.7.egg\\weberror\\evalexception.py', line 431 in respond
      app_iter = self.application(environ, detect_start_response)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\router.py', line 176 in __call__
      response = self.handle_request(request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\tweens.py', line 17 in excview_tween
      response = handler(request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid_tm-0.5-py2.7.egg\\pyramid_tm\\__init__.py', line 100 in tm_tween
      response = handler(request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\router.py', line 153 in handle_request
      response = view_callable(context, request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\config\\views.py', line 186 in _secured_view
      return view(context, request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\fidesysonline\\handlers\\__init__.py', line 32 in decorated_view
      response = view(context, request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\config\\views.py', line 319 in viewresult_to_response
      result = view(context, request)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pyramid-1.2.1-py2.7.egg\\pyramid\\config\\views.py', line 378 in _class_requestonly_view
      response = getattr(inst, attr)()
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\fidesysonline\\handlers\\case.py', line 530 in report
      pdf = pisa.pisaDocument(StringIO(html.encode("UTF-8")), result, encoding="utf-8")
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\document.py', line 127 in pisaDocument
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\platypus\\doctemplate.py', line 880 in build
      self.handle_flowable(flowables)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\platypus\\doctemplate.py', line 763 in handle_flowable
      if frame.add(f, canv, trySplit=self.allowSplitting):
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\platypus\\frames.py', line 174 in _add
      flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=aW-w)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\platypus\\flowables.py', line 108 in drawOn
      self._drawOn(canvas)
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\platypus\\flowables.py', line 89 in _drawOn
      self.draw()#this is the bit you overload
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\xhtml2pdf_reportlab.py', line 677 in draw
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\reportlab_paragraph.py', line 1064 in draw
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\reportlab_paragraph.py', line 1544 in drawPara
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\reportlab_paragraph.py', line 347 in _leftDrawParaLineX
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\reportlab_paragraph.py', line 214 in _putFragLine
    File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\pdfgen\\canvas.py', line 857 in drawImage
      imgObj = pdfdoc.PDFImageXObject(na

me, image, mask=mask)
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\pdfbase\\pdfdoc.py', line 2086 in __init__
  self.loadImageFromSRC(source)   #it is already a PIL Image
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\reportlab-2.5-py2.7-win-amd64.egg\\reportlab\\pdfbase\\pdfdoc.py', line 2173 in loadImageFromSRC
  raw = im.getRGBData()
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\xhtml2pdf-0.0.4-py2.7.egg\\xhtml2pdf\\xhtml2pdf_reportlab.py', line 430 in getRGBData
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pil-1.1.7-py2.7-win-amd64.egg\\Image.py', line 532 in tostring
  self.load()
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pil-1.1.7-py2.7-win-amd64.egg\\ImageFile.py', line 189 in load
  d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File 'B:\\Khakhulin\\Fidesys\\Interface\\Pylons\\FidesysOnline\\~fo\\lib\\site-packages\\pil-1.1.7-py2.7-win-amd64.egg\\Image.py', line 385 in _getdecoder
  raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
4

1 回答 1

0

看起来你有一个没有 zip 支持的 PIL 版本这是一个答案,其中包含指向Windows 的替代 PIL 版本的链接,试试看。

于 2012-09-12T12:19:02.817 回答