Munchkin
Munchkin

Reputation: 4946

ToC level 2 styling on new page, and ToC options

I have two questions:

  1. On this old manual I found some useful toc-options like --toc-depth or --toc-l1-font-size. It seems they aren't available in latest wkhtmltopdf version - so how can I set toc-depth and toc-font-size now?

  2. I want every of my sub-chapters (toc-level 2) begin on a new page:

    • When I create one huge .html file, then the toc is correct (sub-chapter are shown as level-2), but the sub-chapter don't start on a new page.
    • When I create multiple .html files instead (one for every sub-chapter) then my sub-chapter do begin on new pages, but they are all shown as toc level-1.

Upvotes: 1

Views: 1248

Answers (1)

lorenzo-s
lorenzo-s

Reputation: 17010

ToC customization

In the current version, you can use a XSLT file to customize quite anything of the style of the generated ToC. Here are relevant quotes from the documentation:

The table of content is generated via XSLT which means that it can be styled to look however you want it to look. To get an aide of how to do this you can dump the default xslt document by supplying the --dump-default-toc-xsl, and the outline it works on by supplying --dump-outline.

The XSLT document can be specified using the --xsl-style-sheet switch. For example:

wkhtmltopdf toc --xsl-style-sheet my.xsl http://qt-project.org/doc/qt-4.8/qstring.html qstring.pdf

The --dump-default-toc-xsl switch can be used to dump the default XSLT style sheet to stdout. This is a good start for writing your own style sheet

That's what I did to hide specific levels from the ToC. I edited the XSLT file adding a CSS class to <li> (line 40 in the default XSLT) and <ul> (line 55) elements. In that class name I counted the ancestor nodes to get the "level" of depth of the items.

<li class="level-{count(ancestor::*) - 1}">
<ul class="level-{count(ancestor::*) - 1}">

Then I added some CSS rules adding <style> inside <head>:

.level-2, .level-3, .level-4 {
    display: none;
}

Page breaks for sub-chapters

You can place a <div style="page-break-after: always"></div> in yout HTML before your sub-chapters to force them on a new page.

Upvotes: 5

Related Questions