From 6e76edd045c9317734f92b8ad3f9acf8bab4daf5 Mon Sep 17 00:00:00 2001 From: Mathieu de Lorimier Date: Fri, 27 Jan 2017 08:23:45 -0500 Subject: [PATCH] Added pagination start page Added an option to the generation script to dictate on which page the page numbering should start. Option name is paginationStartPage and is 1 based (to start pagination at page 2, the value would be 2) --- lib/scripts/pdf_a4_portrait.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/scripts/pdf_a4_portrait.js b/lib/scripts/pdf_a4_portrait.js index a9197c4..d8772e8 100755 --- a/lib/scripts/pdf_a4_portrait.js +++ b/lib/scripts/pdf_a4_portrait.js @@ -144,6 +144,7 @@ function getContent (page) { // Creates page section // -------------------- function createSection (section, content, options) { + var opts = options options = options[section] || {} var c = content[section] || {} var o = options.contents @@ -153,11 +154,19 @@ function createSection (section, content, options) { height: options.height, contents: phantom.callback(function (pageNum, numPages) { var html = o[pageNum] || c[pageNum] + + var pageNumFinal = pageNum, numPagesFinal = numPages; + if(opts.paginationStartPage && opts.paginationStartPage > 1) { + var pageOffset = opts.paginationStartPage - 1; + pageNumFinal = (pageNumFinal - pageOffset > 0 ? pageNumFinal - pageOffset : ''); + numPagesFinal -= pageOffset; + } + if (pageNum === 1 && !html) html = o.first || c.first if (pageNum === numPages && !html) html = o.last || c.last return (html || o.default || c.default || '') - .replace(/{{page}}/g, pageNum) - .replace(/{{pages}}/g, numPages) + content.styles + .replace(/{{page}}/g, pageNumFinal) + .replace(/{{pages}}/g, numPagesFinal) + content.styles }) } }