Skip to content

PDF: add support for footers and TOC with page numbers #2003

@bitbonk

Description

@bitbonk

The current PDF command and its corresponding pdf.default template does not allow to define a footer for the pages of the document.

Please add support for a footer in a way that we can define custom html for it and also allow us to insert things like page number and total number of pages into that html.

Additionally the generated TOC should optionally have page numbers.

wkthmltopdf that you use has support for all of the above. The challenge is probably, how to add this features without leaking the implementation details of wkhtmltopdf into docfx.

I have managed to add footers with page numbers with this change: bitbonk@1ad6e00

And this footer.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body  onload="substitutePdfVariables()">
    <p>Page <span class="page"></span> of <span class="topage"></span></p>
    <script>
        function substitutePdfVariables() {

            function getParameterByName(name) {
                             var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.href);
                return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
            }

            function substitute(name) {
                var value = getParameterByName(name);
                var elements = document.getElementsByClassName(name);
                for (var i = 0; elements && i < elements.length; i++) {
                    elements[i].textContent = value;
                }
            }

            ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection']
                .forEach(function(param) {
                    substitute(param);
                });
        }
    </script>
</body>
</html>

But this is probably not the right appoach because it would leak wkhtmltopdf into docfx.config and into the template system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pdfProduce PDF as the output format

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions