Skip to content

Commit 4a29881

Browse files
mdelorimiermarcbachmann
authored andcommitted
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)
1 parent 9c38449 commit 4a29881

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/scripts/pdf_a4_portrait.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function getContent (page) {
144144
// Creates page section
145145
// --------------------
146146
function createSection (section, content, options) {
147+
var opts = options
147148
options = options[section] || {}
148149
var c = content[section] || {}
149150
var o = options.contents
@@ -153,11 +154,19 @@ function createSection (section, content, options) {
153154
height: options.height,
154155
contents: phantom.callback(function (pageNum, numPages) {
155156
var html = o[pageNum] || c[pageNum]
157+
158+
var pageNumFinal = pageNum, numPagesFinal = numPages;
159+
if(opts.paginationStartPage && opts.paginationStartPage > 1) {
160+
var pageOffset = opts.paginationStartPage - 1;
161+
pageNumFinal = (pageNumFinal - pageOffset > 0 ? pageNumFinal - pageOffset : '');
162+
numPagesFinal -= pageOffset;
163+
}
164+
156165
if (pageNum === 1 && !html) html = o.first || c.first
157166
if (pageNum === numPages && !html) html = o.last || c.last
158167
return (html || o.default || c.default || '')
159-
.replace(/{{page}}/g, pageNum)
160-
.replace(/{{pages}}/g, numPages) + content.styles
168+
.replace(/{{page}}/g, pageNumFinal)
169+
.replace(/{{pages}}/g, numPagesFinal) + content.styles
161170
})
162171
}
163172
}

0 commit comments

Comments
 (0)