View Single Post
Old 07-31-2016, 02:34 PM   #1
NullNix
Guru
NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.NullNix ought to be getting tired of karma fortunes by now.
 
Posts: 929
Karma: 15576314
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...
NullNix is offline   Reply With Quote