[Conversion HTML-> PDF] PDF header/footer uses wrong _SECTION_ when a single page contains more than one section
Hi, I'm currently the software developer for the U.S. District Court for the District of Kansas. Calibre has been perfect for allowing us to provide PDF and e-book versions of our local rules to the public. It might be a somewhat unconventional use of Calibre, but the ebook-convert tool is -- dare I say -- perfect for this. To that I say thanks!
I've noticed that when converting HTML to PDF, and including a _SECTION_ tag in the header template, the conversion process will use the wrong section when the previous page has more than one section defined. I've attached a PDF with an example. Each "local rule" is defined as a section, but a single page can have more than one rule/section on it (and in our case, usually does). When the last rule on a page takes up the entirety of the next page, that next page's _SECTION_ in the header is wrong; it will use the first defined rule on the previous page as opposed to the last (see the attachment).
Going through the source on github, I've found where I think the problem lies. In:
on line 382-383, it appears the current section is being set to the first instance of a section on the current page, if it has one. I believe it would be more accurate (and would also fix this bug) to set it to the last defined section on the current page. If there was only one section, it would still be equivalent to setting it as the first.
Calibre Version: 1.28
Operating System: Linux (specifically SLES 11)
Attachment example.pdf: The first page contains two defined sections: Rule 83.2.3 and Rule 83.2.4. It would be completely fine if the first page showed 83.2.4 as the section in the header instead. That would also make it so the second page had the correct section displayed in its header.