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.
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up| Related Posts | Replies | Views | Activity | |
|---|---|---|---|---|
|
|
2
Mar 26
|
1051 | ||
|
|
0
Apr 26
|
21 | ||
|
|
1
Apr 25
|
4039 | ||
|
|
2
Mar 25
|
4811 | ||
|
|
4
Nov 24
|
10019 |