how to navigate to a given page number #987
-
I suppose most of the time fpdf is used in a way that pages are created in order. But what if I need to add something to a previous page? In that context, it would be easier to collect that info (chapter titles and page numbers) during document creation, and finally navigate back to your TOC page (i.e., page 2) and write the list of chapters at the end of your script. Is this somehow possible? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you mark the chapters using outlines (bookmarks) you can insert a placeholder using insert_toc_placeholder(). |
Beta Was this translation helpful? Give feedback.
In its core, fpdf2 is still a very simple system. It was designed a long time ago to process pages in a linear fashion, and that aspect hasn't significantly changed since then. You're looking at a straightforward PDF generator, and not at a content management system.
There are some ways to "hack" around the limitations of the system, either through placeholders like for TOCs or the number of pages, or by manipulating the internal counter
self.page
. The latter is probably what you're looking for here, but you need to be aware that it is really more of a workaround than a real feature, and may result in unintended consequences if not handled with care. Those consequences may also change in …