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.
To pytanie dostało ostrzeżenie
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
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj się| Powiązane posty | Odpowiedzi | Widoki | Czynność | |
|---|---|---|---|---|
|
|
2
mar 26
|
1123 | ||
|
|
0
kwi 26
|
21 | ||
|
|
1
kwi 25
|
4338 | ||
|
|
2
mar 25
|
5062 | ||
|
Translate month name in t-esc Qweb report
Rozwiązane
|
|
4
lis 24
|
10227 |