Take the 2-minute tour ×

I have an html document that I'm converting to pdf with PDFKit and wkhtmltopdf. It's rendering fine, but I need to specify a different background for the second and subsequent pages. In other words, the first page will have one background, and the other pages will have a different one.

I have tried implementing javascript like so:

var pdfInfo = {};
var x = document.location.search.substring(1).split('&');
for (var i in x) { var z = x[i].split('=',2); pdfInfo[z[0]] = unescape(z[1]); }
function switchBackground(){
   if (pdfInfo.page>1){ document.body.style.backgroundColor = "#333"; }

This does not work.

share|improve this question
add comment

1 Answer

All pages in output PDF have the same body. So you have to use extra wrappers for each page and something like this:

section:nth-child(odd) {
   background-color: #ccc;
share|improve this answer
add comment

Your Answer


