I’ve been working on a django project recently that generates PDFs from html using the XHTML2PDF library (formerly Pisa). I have html successfully in a pdf in just a couple lines, so overall it’s fantastic, but there are some quirks to get around. I ran into one of these quirks today while trying to put page numbers in my footer template – when it rendered, every page was showing its page number twice (11, 22, 33). My code looked fine; no extra tags, everything was properly formatted, etc, but I could not stop it from happening. Here is my page/footer style and my extremely simple footer markup.
@page {
size: {% if pagesize %}{{pagesize}}{% else %}letter{% endif %};
margin: 1cm;
@frame footer {
-pdf-frame-content: footerContent;
bottom: 1cm;
margin-left: 1cm;
margin-right: 1cm;
margin-top: 0cm;
height: 1.4cm;
}
}
...
<div id="footerContent">Page <pdf:pagenumber /></div>
Finally I got smart and found this answer on the mailing list. Essentially its a bug in the xhtml2pdf parser – without a new line after the
Anyway, this simple change fixed the problem and hopefully you won’t waste any time banging your head on the desk with page 11, 22, etc.
<div id='footerContent'> Page <pdf:pagenumber /> </div>
Recent Comments