问题
I want to generate a pdf with headers, actually I'm working on cygwin andI don't know if something in my code is wrong or not, because I based my code in this examples Creating PDFs with django (wkhtmltopdf). This is my code:
views.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',
)
my html code may be simple but it shows something and I render a PDF successfuly but not the header.
header.html:
<html>
<head>
</head>
<body>
<img src="http://www.someplaceintheworld/some.png" alt="some logo" />
</body>
</html>
my urls.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'),
)
回答1:
I found the answer here https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1645 only need put the doctype to each html.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src="http://www.someplaceintheworld/some.png" alt="some logo" />
</body>
</html>
来源:https://stackoverflow.com/questions/33512009/how-to-add-headers-and-footers-with-django-wkhtmltopdf-in-my-class-based-views-w