Forum How do I...?

Break @page with break "page-break-before" with breaked pages having @page style.

pauldotknopf
I am generating a PDF for printing left-to-right.

I have a "@page LastPage" that needs to be breaked at the very end, and the end of the book.

@page LastPage {
  background: red;
}

.last-page {
  page: LastPage;
  page-break-before: right;
}


<div class="last-page">
  end of book
</div>


This works perfectly, except I also need to clear out footers/headers on the last page.

The problem is the pages that are skipped when breaking do not get the @page style applied.

Edited by pauldotknopf

mikeday
Do you want the last page of the document to be blank, or the second last page to be blank?
pauldotknopf
Either the last page, or the second to last page.

But, I need any "breaked" pages to also have the @page style applied, so that I can clear footers/headers.
mikeday
You can use @page:blank to match the inserted blank pages.
pauldotknopf
I can ALMOST acheive what I want with this.

@page LastPage {
  background: red;
}

.last-page:before {
  content: " ";
  white-space: pre;
}

.last-page {
  page: LastPage;
  .content {
    page-break-before: right;
  }
}


<div class="last-page">
  <div class="content">
     end of book
  </div>
</div>


In the code above, the @page gets used for all previous pages, but there is an extra set of generated pages with this approach, leaving either 1 blank page or 2 blank pages.
pauldotknopf
@page:blank applies globally, I need the style applied within the context of the pages that are breaked.
pauldotknopf
Here is how my pages are layed out.

1. @page
2. @page
3. @page
4. @page
5. @LastPage:blank ? - this doesn't get styled.
6. @LastPage - breaked

I can style number 5 with @page:blank, but I don't want it to effect the other blank pages in the document.
pauldotknopf
I've tried this. Doesn't work.

@page LastPage {
  background: red;
}

@page LastPage:blank {
  background: blue; /*DOESN'T color the breaked page!*/
}

.last-page {
  page: LastPage;
  page-break-before: right;
}
mikeday
Ah this might be a bit tricky if the :blank page is not included in the LastPage named page group, since it technically precedes it. Do you have other blank pages in the document that need a different styling?
pauldotknopf
Yeah, this is why I was trying this approach.

With that said, I could refactor what I am doing a little bit so that I could use @page:blank. I'll go ahead and start that. I was hoping I was missing something stupid :)

Thanks for the quick response. I love your product!