it interacts with and modifies the layout (and the DOM structure). Once layout is
handler - see Event handling. However, this time it is only allowed
to inspect the layout and cannot modify the DOM.
A problematic situation arises when you want to modify your document after layout has finished - a typical scenario would be when you want an index to be created with correct page numbers. The content depends on the layout of the document itself.
Typically Prince is run a first time to prepare the layout of the document and
append it to the document with the help of the
console.log() - see
Now the document would be ready for generating the PDF - Prince is run a second time, producing the desired document.
Here is a minimalistic two-pass solution where the document is adorned with a ToC and index:
Another use of the two-pass solution is to create changebars - see the description here.