django-wkhtmltopdf
django-wkhtmltopdf copied to clipboard
Page header and Page content overlapped but not footer.
In my generated pdf page header template (not table header) is overlapped with content added in page. . What might be the problem ?
I have the same issue. Did you find a solution?
What fixed it for me was creating a container in the header template's body with the height set to the same value as margin-top).
<body>
<div style="height: {{template.header_height}}pt;">
</div>
</body>
from wkhtmltopdf.views import PDFTemplateResponse
class Pdf():
def __init__(self, request, template, context):
self.request = request
self.template = template
self.margin_top = 45
self.margin_left = self.margin_bottom = self.margin_right = 10
self.show_content_in_browser = True
self.context = context
self.filename = 'new_file.pdf'
self.header = 'print/header.html'
self.footer = 'print/footer.html'
def response(self):
return PDFTemplateResponse(request=self.request,
template=self.template,
filename=self.filename,
context=self.context,
show_content_in_browser=self.show_content_in_browser,
header_template=self.header,
footer_template=self.footer,
cmd_options={
'header-spacing': 40,
'margin-top': self.margin_top,
'margin-left': self.margin_left,
'margin-right': self.margin_right,
'margin-bottom': self.margin_bottom
}
)
Header spacing and margin top