Dynamic section name in EvoHtmlToPdf header

121 Views Asked by At

Is there a way in EvoHtmlToPdf to display the section/subsection of a page in the header/footer (i.e. the text of the "current" h1/h2 tag)?

With wkhtmltopdf and other tools, it is possible to replace special tags via JavaScript and the HTML header template (as described here for example Dynamic section name in wicked_pdf header).

Unfortunately, such a solution does not seem to work with EvoHtmlToPdf.

Here's the HTML code of my header template:

<html id="headerFooterHtml">
<head>
    <script>
        function substHeaderFooter(){
            var vars={};
            var searchString = document.location.search;
            var debugMessage = document.getElementById("showJavaScriptWasExecuted");
            if (debugMessage)
                debugMessage.textContent = "Search string: ["+ searchString + "]";
            var search_list = searchString.substring(1).split('&');
            for(var i in search_list){
                var content=search_list[i].split('=',2);
                vars[content[0]] = decodeQueryParam(content[1]);
            }
            var tags=['section','subsection'];
            for(var i in tags){
                 var name = tags[i], 
                    classElements = document.getElementsByClassName(name);
                 for(var j=0; j<classElements.length; ++j){
                    classElements[j].textContent = vars[name];
                 }
            }
        }
    </script>
</head>
<body id="headerFooterBody" onload="substHeaderFooter()">
    <div id="showJavaScriptWasExecuted"></div>
    <div id="sections">{section} / {subsection}</div>
</body>    

Resulting header in PDF

I already added the EvoHtmlToPdf PrepareRenderPdfPageDelegate event handler to my code (if that's the way I have to go) but I don't know how to access the section of the current page there...

Thanks in advance for your help!

0

There are 0 best solutions below