我想生成一个带有标题的pdf,实际上我正在处理cygwin,我不知道我的代码中是否有错误,因为我的代码是基于这个示例Creating PDFs with django (wkhtmltopdf)。这是我的代码:
在视图.py在
from django.views.generic import View
from wkhtmltopdf.views import PDFTemplateResponse
GenerateReportPdf(View):
def __init__(self):
self.template = 'pdf_template.html'
def get(self, request):
...
response = PDFTemplateResponse(
request=request,
template=self.template,
filename='report.pdf',
context=self.context,
show_content_in_browser=True,
cmd_options={'margin-top': 30,},
header_template='header.html',
)
我的html代码可能很简单,但它显示了一些东西,我成功地呈现了一个PDF文件,但没有显示标题。
页眉.html以下内容:
我的网址.py以下内容:
from django.conf.urls import patterns, url
from django.contrib.auth.decorators import login_required
from . import views
urlpatterns = patterns('',
url(r'^$', login_required(views.GenerateReportPdf.as_view()), name='index'),
)
我在这里找到了答案https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1645只需将doctype放入每个html即可。在
相关问题 更多 >
编程相关推荐