[Conversion HTML-> PDF] PDF header/footer uses wrong _SECTION_ when a single page contains more than one section

Bug #1295236 reported by Michael Dreiling
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

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:

    /src/calibre/ebooks/pdf/render/from_html.py

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.

Revision history for this message
Michael Dreiling (michael-dreiling) wrote :
Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1295236

The problem isnt that the section used is the first section. That
behavior is correct. The problem is that if a page with no sections
follows a page with multiple sections, the page with no sections gets
its section set to the first section on the previous page, instead of
the last section.

I have committed a fix for that, though I haven't tested it, I leave
that to you.

Revision history for this message
Kovid Goyal (kovid) wrote : Fixed in master

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.