Django pisa - pagenumber for only two or more pages - show the total number of pages

Is it possible to show pagenumber with django pisa for only two or more pages? The template for displaying pagenumber is as follows:

<div id="footerContent">
   <p>Page <pdf:pagenumber></p>
</div>

I think it is necessary to get the number of pages before they are processed by pisa. Any option to use an if / else statement like this pseudo:

if pages > 1:
 ...
else:
 ...

If you want to display, for example. Page 1/5 (page one of five) also need to get the number of pages ?! There is no solution in Pisa for this?

+3
source share
3 answers

, , . , pisa :

import ho.pisa as pisa

import xhtml2pdf.pisa as pisa 

xhtml2pdf

pip install xhtml2pdf

<div id="footerContent">
    {%block page_foot%}
        Page <pdf:pagenumber> / <pdf:pagecount>
    {%endblock%}
</div>
+2

python-pisa. . pisa xhtml2pdf github, .

https://github.com/chrisglass/xhtml2pdf

:

<div id="footerContent">
  "Page: <pdf:pagenumber> / <pdf:pagecount>
</div>
+1

, , https://github.com/chrisglass/xhtml2pdf. , , , :

<h1 style="display:none">PAGECOUNT</h1>

CSS h1 -

h1 {
    page-break-before:always;
}

Now you can get the number of pages using

<your-html-string>.count('PAGECOUNT') + 1
+1
source

All Articles