Skip to content

Conversation

@mdelorimier
Copy link
Contributor

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)

Sorry if this pull request is made the wrong way, it is my first one and made to the best of my knowlege.

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)
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.

@marcbachmann
Copy link
Owner

Thanks for your pr. This is definitely something we can take in.
There are a few changes needed to improve the readability. I'll comment inline.

var pageNumFinal = pageNum, numPagesFinal = numPages;
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.

if(opts.paginationStartPage && opts.paginationStartPage > 1) {
var pageOffset = opts.paginationStartPage - 1;
pageNumFinal = (pageNumFinal - pageOffset > 0 ? pageNumFinal - pageOffset : '');
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.

@marcbachmann
Copy link
Owner

Sorry if this pull request is made the wrong way, it is my first one and made to the best of my knowlege.

Oh, do you know how to rebase?
First make sure that you don't have any uncommited changes.
It's best if you push everything. Then you can run

git pull --rebase origin master

If there's no conflict, you can force push to overwite your changes with git push -f.

@maksim-anikeev
Copy link

Hi, guys. Could you tell please status this pr now?

@marcbachmann
Copy link
Owner

I'll merge that in here: #258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants