I’m generating a PDF using TCPDF and lots of writeHTML() calls. Sometimes when I have header tags (h1, h2, etc.) in the HTML, the headers are at the bottom of a page and the corresponding content gets broken up and pushed to the next page.
Is there any way to have TCPDF either 1) Have the header “keep with” the following content, or 2) Have headers (and only headers) pushed to the next page if some percent (say 20%) or less of the page space is available?
I’ve tried breaking up the HTML, but ended up passing unclosed tags to writeHTML() and it died.
I implemented Orbling’s solution, but couldn’t quite get it working. Given that, for the moment I will post my working, but more hackish solution, and try to return to Orbling’s if I find the time. I will hold out on accepting either answer for a couple days.
My basic approach was to replace all h1-h6 tags (using a regex), and prepend them with
<tcpdf method="MaybeSkipPage" />, which I implemented by extending the TCPDF class.In code: