PDF Output: Enable using javascript inside header and footer templates

This commit is contained in:
Kovid Goyal 2014-03-23 11:41:21 +05:30
parent bbc7535718
commit 1fa5a5af1a
3 changed files with 13 additions and 1 deletions

View File

@ -840,7 +840,7 @@ template::
This will display the title at the left and the author at the right, in a font
size smaller than the main text.
Finally, you can also use the current section in templates, as shown below::
You can also use the current section in templates, as shown below::
<p style="text-align:right">_SECTION_</p>
@ -850,6 +850,12 @@ Outline). If the document has no table of contents then it will be replaced by
empty text. If a single PDF page has multiple sections, the first section on
the page will be used.
You can even use javascript inside the header and footer templates, for
example, the following template will cause page numbers to start at 4 instead
of 1::
<p id="pagenum" style="text-align:center;"></p><script>document.getElementById("pagenum").innerHTML = "" + (_PAGENUM_ + 3)</script>
.. note:: When adding headers and footers make sure you set the page top and
bottom margins to large enough values, under the Page Setup section of the
conversion dialog.

Binary file not shown.

View File

@ -8,6 +8,10 @@
log = window.calibre_utils.log
runscripts = (parent) ->
for script in parent.getElementsByTagName('script')
eval(script.text || script.textContent || script.innerHTML || '')
class PagedDisplay
# This class is a namespace to expose functions via the
# window.paged_display object. The most important functions are:
@ -238,8 +242,10 @@ class PagedDisplay
section = py_bridge.section()
if this.header != null
this.header.innerHTML = this.header_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"")
runscripts(this.header)
if this.footer != null
this.footer.innerHTML = this.footer_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"")
runscripts(this.footer)
fit_images: () ->
# Ensure no images are wider than the available width in a column. Note