2013-03-03 2 views
2

웹킷을 사용하는 놀라운 html converter wkhtmltopdf을 방금 발견했습니다. 난 내 dev에 기계와 그 간단한 노력하고 잘 작동합니다.python과 wkhtmltopdf로 된 HTML to

어떻게 이것을 장고 기반 사이트와 통합 할 수 있습니까?

나는 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) 
  • 그 파이썬 바인딩을 설치 한 후, 어떻게 그들을 사용합니까? 어떤 전화를 할 수 있습니까?

  • 결과로 나타나는 pdf 파일을 hd에 저장해야합니까? 아니면 무언가가있는 뷰에서 스트리밍 할 수 있습니까? 예를 들어

:

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

답변

4

나는이 목적을 위해 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'), 
    # ... 
)