EvoHtmlToPdf 标头中的动态部分名称

发布于 2025-01-12 13:34:24 字数 1805 浏览 3 评论 0原文

EvoHtmlToPdf 中有没有办法在页眉/页脚中显示页面的部分/子部分(即“当前”h1/h2 标签的文本)?

使用 wkhtmltopdf 和其他工具,可以通过 JavaScript 和 HTML 标头模板替换特殊标签(如此处所述,例如 wicked_pdf 标题中的动态部分名称)。

不幸的是,这样的解决方案似乎不适用于 EvoHtmlToPdf。

这是我的标题模板的 HTML 代码:

<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>    

PDF 中的结果标题

我已经添加了 EvoHtmlToPdf PrepareRenderPdfPageDelegate 事件处理程序到我的代码(如果这是我必须走的路),但我不知道如何访问当前页面的部分...

谢谢提前寻求您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文