From 1fa5a5af1aee6591d8ac79a8e610ef92678b02be Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 23 Mar 2014 11:41:21 +0530 Subject: [PATCH] PDF Output: Enable using javascript inside header and footer templates --- manual/conversion.rst | 8 +++++++- resources/compiled_coffeescript.zip | Bin 81197 -> 81622 bytes src/calibre/ebooks/oeb/display/paged.coffee | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/manual/conversion.rst b/manual/conversion.rst index 5576209e01..ad7440e99f 100644 --- a/manual/conversion.rst +++ b/manual/conversion.rst @@ -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::

_SECTION_

@@ -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:: + +

+ .. 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. diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index e404bffba289e3d1009a0a53189efb82e702db00..69db556d5f71ed039e15bffa957fd020e1aaf28b 100644 GIT binary patch delta 428 zcmZ4ci{;v1mJJhT@F~QUyR3UHx!Nd!fx#$Ya>94X$=hf2@aQNMmF5*E7iAWd6i>d8 zt)YkDD%dKdmF6XvWaj5-6eJd<=9OqFRC6f+L0Mvv0z}XBRicdQ%s|=cg4&Ey91uZu z&FS|=8H3p%yvdC0!v66^sl}x^CB=FLrNtQ{2Nqk!y@+xv7TR~{Cf9JQZk zvh?vy@<7SdlG36)BsCf(8JWd;Y5DmjsYR0w-|B7tbo^ieS}09FXu%lC^zp~!`cl#9 zhL(&*%+c(O)6cUq%1m#vWYl6hATWKMC8Iaf1jXsUEgAKgZdgp$wqiV@lVogeVU(O| zWNwgRU~FQZmTH)6U}0=*nv`l`W}a%2oMx0}k!+f1rlg~wG`X=vH8-hLfy$HkJwM1b7Irv zovT$h&pvsu08R1qEGx!HCXesa4XqeOr{A(-G-BGsI-Sp&(VbbGpK|9Hl$8kZW@Tdl0xlqY#l*m%Z_dc@kEvQ|a$~97^dHuY3pCPFjg1VGjm%R` pEG#UNEmPA>jZ#gFOp;7e6Ah9q%#2KvOwCM84N|usuwfKq0st@aMAHBO diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 946edd619b..8ed5ae0da1 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -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