Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/scripts/pdf_a4_portrait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split up multiple assignments onto multiple lines.
This didn't throw an error in the linting script because only bin/index.js was tested.
I've created a pr here that fixes the config https://github.com/marcbachmann/node-html-pdf/pull/230/files

Can you please rebase and apply those changes.

if(opts.paginationStartPage && opts.paginationStartPage > 1) {
var pageOffset = opts.paginationStartPage - 1;
pageNumFinal = (pageNumFinal - pageOffset > 0 ? pageNumFinal - pageOffset : '');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange that you have an empty string as fallback.
The ternary also looks strange. Please use (pageNumFinal - pageOffset > 0) ? pageNumFinal - pageOffset : ''.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. The empty string is to actualy print out a blank for cover pages and such

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would look nicer if we have that fallback in the replace method.

numPagesFinal -= pageOffset;
Copy link
Owner

@marcbachmann marcbachmann Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to never use -=. More explicit is better.
Would be nice if we can calculate those numbers differently.

e.g.

var paginationStartPage = (opts.paginationStartPage >  1) ? opts.paginationStartPage : 1
var pageNumFinal = (pageNum - pageOffset > 0) ? pageNumFinal - pageOffset : ''
var numPagesFinal = numPages - (paginationStartPage - 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will make those changes.
Also would be nice if we could have header and footer for the current page. E.g. if you have, in a .page element a .header or .footet, it be used as the header/footer for that specific page.

}

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
})
}
}
Expand Down