Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Header/Footer to each page in Webshot #138

Open
bsbechtel opened this issue Feb 17, 2016 · 1 comment
Open

Adding Header/Footer to each page in Webshot #138

bsbechtel opened this issue Feb 17, 2016 · 1 comment

Comments

@bsbechtel
Copy link

I'm trying to add a header and footer to each page of a pdf I am creating using webshot. Is it possible to modify the phantomPage options handler function to handle callbacks, per this SO question?

@bsbechtel
Copy link
Author

So I spent the day trying to figure this out, as I really needed to be able to modify the header/footers in my project. the question above using eval() didn't work. However, I wrote the following modification to be inserted on line 70 of webshot.phantom.js:

if (key === "paperSize" && page[key] && page[key].header && page[key].header.contents) {
    var header = {
      "height": page[key].header.height,
      "contents": phantom.callback(function() {return options.paperSize.header.contents;})
    }
    page.paperSize.header = header;
  }
  if (key === "paperSize" && page[key] && page[key].footer && page[key].footer.contents) {
    var footer = {
      "height": page[key].footer.height,
      "contents": phantom.callback(function() {return options.paperSize.footer.contents;})
    }
    page[key].footer = footer
  }
  if (key === "paperSize") {
    page.paperSize = {
      "format": options.paperSize.format,
      "orientation": options.paperSize.orientation,
      "margin": options.paperSize.margin,
      "header": header,
      "footer": footer
    }
  } 

The above works for my code, but it is missing a few additional paperSize options to work as a general solution. It also can't handle the pageNum and numPages arguments, but it is an improvement that I think can be helpful. I've never submitted a pull request in git before, but think we can merge this into the main branch?

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

No branches or pull requests

1 participant