2π
I had problem with adding a counter that would tell me what page number i was looking at out of the total amount of pages in the document. It got it to work when i switch the pisa import from:
import ho.pisa as pisa
to
import xhtml2pdf.pisa as pisa
Install xhtml2pdf with pip
pip install xhtml2pdf
This is what my footer looks like now
<div id="footerContent">
{%block page_foot%}
Page <pdf:pagenumber> / <pdf:pagecount>
{%endblock%}
</div>
π€Erik Perttu
1π
This is not possible in the current version of python-pisa. There is however some patches for it. If you use the version of pisa or xhtml2pdf from this github you will be able to get total number of pages.
https://github.com/chrisglass/xhtml2pdf
My template footer looks like this:
<div id="footerContent">
"Page: <pdf:pagenumber> / <pdf:pagecount>
</div>
- [Django]-Django: Any way to sort on model method in admin interface?
- [Django]-Summing up values from database in DJANGO template
- [Django]-Django : extract a path from a full URL
- [Django]-Django and Channels and ASGI Thread Problem
- [Django]-How make conditional expression on Django with default value of object?
1π
I think you can do it without using https://github.com/chrisglass/xhtml2pdf.
What i did is,
i use page break as below:
<h1 style="display:none">PAGECOUNT</h1>
and CSS for h1 is
h1 {
page-break-before:always;
}
Now, you can get page count using
<your-html-string>.count('PAGECOUNT') + 1
π€vicky
- [Django]-How to make Router display urls from Multiple apps in Browsable API root view in Django REST Framework?
- [Django]-Formatting TimeField
- [Django]-Django save or update model
- [Django]-Filter in django: the last post of each user
Source:stackexchange.com