Forum How do I...?

How do I re-trigger function registered via registerPostLayoutFunc in Prince16?

MartinM
Hi,

I need to fill an empty space of undetermined length at the end of the page with dummy lines. After several unsuccessful attempts I came across the registerPostLayoutFunc method, which should be the exact tool for the task.

BUT... According to the documentation it should re-trigger itself if last run modified the DOM structure. The problem is it only runs once.

The idea is as follows:
I am appending a bunch of dummy lines at the end of the page which makes the content overlap on 2 pages and then I am trying to delete one line of dummy text via el.removeChild(el.lastElementChild) in each run of post layout function until the number of pages (Prince.pageCount) is 1.

But, as I've said, the post layout function only runs once (even if I return true when pageCount > 1) and then the PDF is generated.

What do I need to do to re-trigger the function after each layout pass?
wangp
You need to call registerPostLayoutFunc again in the post layout function to request another pass. That is probably what is missing.
howcome
The "float-tail" property experimentally tries to address this:

https://css4.pub/2022/float/#dropping-the-tail

The approach is to specify more page floats than you will need, then delete the ones that do not en up on a page with regular content.

It would be interesting to hear if you can use this feature. And, which new kewords would make sense?
MartinM
To howcome: Thank you for pointing this out. It's something completely new to me, I will check.

To wangp: Big THANK YOU! I already tried this technique before and it deleted all dummy lines because it did not update number of pages. But based on your comment I tried again and voila - it actually does work! Not sure what is different compared to my previous attempt, but the important thing is it finally works :)

Final solution (at least for now):
  • I have a function check() which does the dummy lines removal based on current number of pages.
  • I register this function via registerPostLayoutFunc(check).
  • If number of pages > 1 then I call registerPostLayoutFunc(check) again directly within check function itself.
  • Otherwise it just returns.