2

我刚刚找到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 是否必须保存到 hd 或者我可以用什么东西把它从视图中流出来?

例如:

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

1 回答 1

4

为此,我会推荐django-wkhtmltopdf。他们的使用文档提供了一些关于如何集成的示例:

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'),
    # ...
)
于 2013-03-03T17:28:55.777 回答