xhtml2pdf: `` and `` causes page number to be printed twice

I have strange issues with the above tags inside html templates.

Let’s say I have <div id="footer_pagenumber">Page <pdf:pagenumber/></div> then the page number is printed twice (11 instead of 1). If I add a single whitespace after the <pdf:pagenumber/> tag, the number is fine. The same problem applies to <pdf:pagecount/>.

Another issue is with <pdf:pagecount/> is that if I use this tag, the background image of my PDF is not rendered anymore.

Tested with xhtml2pdf v0.0.5, reportlab 2.7 and Pillow 2.0.0.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 20 (2 by maintainers)

Most upvoted comments

to “correct” just put &nbsp; &nbsp; => this is the encode space <pdf:pagenumber> of <pdf:pagecount>&nbsp;

I also experience it but I found a workaround. It was good enough to put one space just after the tag, i.e. change --<pdf:pagenumber>-- to --<pdf:pagenumber> -- (double hypen is there to make the space visible).

+11

my test case, “Page 1 of 5”:

code: <div id="header">Page <pdf:pagenumber> of <pdf:pagecount></div> result: Page 1 of 55 code: <div id="header">Page <pdf:pagenumber></div> result: Page 11

but there is a solution: code: <div id="header">Page <pdf:pagenumber> of <pdf:pagecount> </div> result: Page 1 of 5 and code: <div id="header">Page <pdf:pagenumber> </div> result: Page 1

I was able to fix by adding a new line like

<div id="footer_content">(c) - <pdf:pagenumber>
    </div>

It was stated on the document https://xhtml2pdf.readthedocs.io/en/latest/format_html.html#example-with-2-static-frames-and-1-content-frame

  • With a hashtag Developer’s note:

Un parche que soluciona, pero no es la manera correcta, es ocultar el segundo pdf:pagecount, ya que por lo visto el ultimo se esta repitiendo dando como resultado 1 de N

Página <pdf:pagenumber> de <pdf:pagecount> <pdf:pagecount style='display:none'>