I am creating a QWeb report, but I’m facing a challenge with the Table of Contents (TOC) page. What is the best approach to handle this, especially regarding page numbers? Since the PDF sections are dynamic, the table needs to render accordingly with the correct page numbers for each section.
Deze vraag is gerapporteerd
Hi Izma,
In standard Odoo QWeb → wkhtmltopdf, you can’t reliably know final page numbers while rendering the same template (pagination happens only after wkhtmltopdf lays out the whole HTML, and your sections are dynamic).
Best-practice options:
Prefer PDF bookmarks instead of printed page numbers
Use real headings (<h1>…</h1>, <h2>…</h2>) so the PDF viewer shows a clickable TOC (most users use this anyway). This avoids the “dynamic pages” problem entirely.
If you must print page numbers in the TOC: do a 2-pass / post-process approach
Pass 1: Render the PDF without the TOC.
Compute pages per section: split/measure pages (PyPDF2/pikepdf), track where each section starts.
Pass 2: Render a TOC page with the computed page numbers and prepend/merge it with the original PDF.
That’s the only robust way in Odoo when sections can expand/contract. Trying to do it “in pure QWeb” will always break for some data because pagination is not deterministic until PDF generation finishes.
I hope it works. Still, if you face any issue, then please feel free to contact: santosh.sekwadia@zehntech.com
Regards,
Hope it heps.
I hope you are doing well
Use <h1>/<h2> in QWeb + wkhtmltopdf's --toc flag.
QWeb Template:
Python Override:
wkhtmltopdf auto-generates a TOC page with correct page numbers from your headings.
I hope this information helps you
Thanks & Regards,
Kunjan Patel
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden| Gerelateerde posts | Antwoorden | Weergaven | Activiteit | |
|---|---|---|---|---|
|
|
2
mrt. 26
|
1123 | ||
|
|
0
apr. 26
|
21 | ||
|
|
1
apr. 25
|
4348 | ||
|
|
2
mrt. 25
|
5065 | ||
|
|
4
nov. 24
|
10230 |