diff --git a/lib/scripts/pdf_a4_portrait.js b/lib/scripts/pdf_a4_portrait.js index a9197c4..243fcd6 100755 --- a/lib/scripts/pdf_a4_portrait.js +++ b/lib/scripts/pdf_a4_portrait.js @@ -153,11 +153,16 @@ function createSection (section, content, options) { height: options.height, contents: phantom.callback(function (pageNum, numPages) { var html = o[pageNum] || c[pageNum] + + var pageOffset = (options.paginationStartPage > 1) ? options.paginationStartPage : 1 + var pageNumFinal = (pageNum - pageOffset > 0) ? pageNum - pageOffset : '' + var numPagesFinal = numPages - (pageOffset - 1) + 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 }) } }