【问题标题】:HTML to PDF with python and wkhtmltopdf使用 python 和 wkhtmltopdf HTML 到 PDF
【发布时间】:2013-03-03 17:10:42
【问题描述】:

我刚刚找到wkhtmltopdf,使用 webkit 的惊人的 html 转换器。我已经在我的开发机器上尝试过它,它很简单而且效果很好。

如何最好地与基于 django 的站点集成?

我找到了python bindings,但他们假定对如何安装我没有的东西有一定程度的了解。例如

you need libwkhtmltox.* somewhere in your LD path (/usr/local/lib)
you need the directory src/include/wkhtmltox from wkhtmltopdf
    somewhere on your include path (/usr/local/include)
  • 在安装了这些 python 绑定之后,我该如何使用它们?我可以拨打哪些电话?

  • 生成的 pdf 是否必须保存到高清文件中,或者我可以将其从视图中流出来吗?

例如:

response['Content-Disposition'] = 'attachment; filename='+letter_name
response['Content-Type'] = 'Content-type: application/octet-stream'
response['Content-Length'] = bytes
return response

【问题讨论】:

    标签: python django wkhtmltopdf python-bindings


    【解决方案1】:

    我会为此推荐django-wkhtmltopdf。他们的usage documentation 给出了一些关于如何集成的例子:

    from django.conf.urls.defaults import *
    from wkhtmltopdf.views import PDFTemplateView
    
    
    urlpatterns = patterns('',
        # ...
        url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
                                               filename='my_pdf.pdf'), name='pdf'),
        # ...
    )
    

    【讨论】:

      猜你喜欢
      • 2016-10-07
      • 2021-02-01
      • 2014-01-06
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      相关资源
      最近更新 更多