django-wkhtmltopdf icon indicating copy to clipboard operation
django-wkhtmltopdf copied to clipboard

Page header and Page content overlapped but not footer.

Open prdpspkt opened this issue 4 years ago • 4 comments

In my generated pdf page header template (not table header) is overlapped with content added in page. . What might be the problem ?

prdpspkt avatar Nov 15 '20 14:11 prdpspkt

I have the same issue. Did you find a solution?

gijsriet avatar Dec 23 '20 12:12 gijsriet

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>

gijsriet avatar Dec 23 '20 14:12 gijsriet

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
                                   }
                                   )

prdpspkt avatar Dec 23 '20 14:12 prdpspkt

Header spacing and margin top

prdpspkt avatar Dec 23 '20 14:12 prdpspkt