Search code examples
javacssjsoupopenhtmltopdf

Different headers when printing


I need to export multiple HTML files into a single PDF one. I'm using @page rules to apply a header.

I need to :

  • Display the pagecount ( page n out of total)

  • Display a different title in the header for each original HTML document

What I tried :

  • Exporting each HTML separately: I get the good title but the pagecount is relative to the current HTML, not the global total.

  • Using jsoup to gather every HTML in one document before exporting: I get the good pagecount but can't select which title to apply in the print header

I know about @page:first and @page:last but would like to be able to apply different styles for every page in between.


Solution

  • I found a solution !

    You can specify some content to be on a named page :

    @page A { @top-left { content:"..." } }

    div-A { page: A; }

    <div-A> Content that has a specific header </div-A>

    Don't forget to apply some rules like "page-break-after: always"