|
|
Thread Tools | Search this Thread |
07-31-2016, 02:34 PM | #1 |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Ancestor element text extraction (chapter titles) in PDF header templates
So I'm trying to turn an ebook into a PDF for various people who want paper copies (some people are stuck in the past or something ). I've resigned myself to the fact that I can't put distinct content in the headers on facing pages, but I'd like to put the chapter title (the contents of the closest preceding h1 element) into each heading. Reactivating rusted ten-years-unused XPath neurons, I've tried (ignore the spurious space inserted in '.innerHTML', I don't know what the forum software is playing at)
--pdf-header-template '<p id="chaptitle" style="text-align:center;"></p><script>document.getElementById("chaptitle").inn erHTML = document.evaluate("ancestor-or-self::h1[last()]/text()", "", null, XPathResult.STRING_TYPE,null).stringValue;</script>' but unfortunately this yields an immense stream of JS: NotSupportedError: DOM Exception 9: The implementation did not support the requested type of object or operation. and no header content at all. Further, it seems that *any* use of ancestor-or-self in this construction has the same effect. Has anyone done this sort of thing before (extracted text, attribute content, or something similar related to a node ancestral to the content on the current page during PDF conversion)? What am I doing wrong? It's probably something really stupid... |
07-31-2016, 02:53 PM | #2 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You want to put chapter titles in the header, look at the manual, it has examples of doing that.
http://manual.calibre-ebook.com/conv...verting-to-pdf See the use of _SECTION_ |
Advert | |
|
07-31-2016, 04:23 PM | #3 | |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Quote:
Calibre is, as ever, the king of pre-emptive feature additions! and also of stunningly fast responses to questions I needed to do a few regex substitutions on it (don't want the chapter number in there, if there is one) but that works very well, thank you! |
|
07-31-2016, 07:12 PM | #4 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
The forum software breaks up words that are too long once they reach the cutoff length. But for the purposes of code, you can use the [CODE][/CODE]* tags (which also monospaces it). * -- Rendered visible through the (now recursive) power of [NOPARSE][/NOPARSE] |
08-01-2016, 06:35 AM | #5 | |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Quote:
|
|
Advert | |
|
08-01-2016, 11:49 AM | #6 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
08-07-2016, 07:48 AM | #7 |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Aside: the attached patch gives you a _TL_SECTION_ which is nailed to top-level section names only. It's quite nasty: in particular the code in do_paged_render() is too repetitive. But it works, and lets you do things in the header like arranging to populate it only when the top-level section has not changed since the last header laid out (-> the last page): this gives you the behaviour you get in most real books, where the header is silently omitted when new chapters start.
(MobileRead's anaemic attachment system won't let me upload it without calling it .txt, not .diff, but it is still a diff. Ugh. Bring back mailing lists, all is forgiven.) |
08-08-2016, 12:23 AM | #8 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
08-13-2016, 07:45 AM | #9 | |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Quote:
Thank you |
|
08-13-2016, 07:46 AM | #10 | |
Guru
Posts: 916
Karma: 13928438
Join Date: Jan 2013
Location: Ely, Cambridgeshire, UK
Device: Kindle Oasis 3, Kindle Oasis 1
|
Hm, there's a typo in the manual section describing it, though:
Quote:
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
no text extraction for pdf with images and OCR | fxp33 | Conversion | 7 | 12-15-2015 07:22 AM |
ePub->pdf: How to narrow space between header and book text? | EbokJunkie | Conversion | 17 | 01-07-2015 02:17 AM |
Need Text extraction engin from editable PDF | qsipl | Workshop | 17 | 05-23-2014 07:26 PM |
Image as Header for Chapter | Peter21 | Sigil | 43 | 12-07-2013 02:31 PM |
PDF Conversion - Removing Header / Footer Text | heb | Sony Reader | 9 | 07-11-2010 11:02 PM |