【问题标题】:Hide Footer on first page在第一页隐藏页脚
【发布时间】:2015-03-21 10:13:27
【问题描述】:

是否可以隐藏特定页面的 TuesPechkin 文档的页眉/页脚。我希望在 PDF 文档的第一页上忽略页眉和页脚,但找不到实现此目的的方法。

文件设置如下:

var document = new HtmlToPdfDocument
        {
            GlobalSettings =
            {
                ProduceOutline = true,
                DocumentTitle = "My Report",
                PaperSize = PaperKind.A4, // Implicit conversion to PechkinPaperSize
                Margins =
                {
                    All = 1.375,
                    Unit = Unit.Centimeters
                }
            },
            Objects =
            {
                new ObjectSettings
                {
                    HtmlText = html,
                    WebSettings = new WebSettings {UserStyleSheet = "~/Content/Site.css"},
                    HeaderSettings = new HeaderSettings()
                        {
                            FontSize = 8,
                            LeftText = "My report", 
                            RightText = "2014"
                        },
                    FooterSettings = new FooterSettings()
                    {
                        FontSize = 8,
                        CenterText = "Page [page] of [topage]"
                    }
                }
            }
        };

【问题讨论】:

    标签: c# pdf-generation wkhtmltopdf tuespechkin


    【解决方案1】:

    API 似乎不支持这一点。但是,我为 WKHTMLTOPDF 找到了一种解决方法here,它可能对您有用。

    将以下 HTML 放入文件中,并在页脚设置中引用此文件。

    <html>  
    <head>  
    <script>  
       function subst() {  
          var vars = {};  
    
          // explode the URL query string  
          var x = document.location.search.substring(1).split('&');  
    
          // loop through each query string segment and get keys/values  
          for (var i in x)  
          {  
             var z = x[i].split('=',2);  
             vars[z[0]] = unescape(z[1]);  
          }  
    
          // an array of all the parameters passed into the footer file  
          var x = ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];  
    
          // each page will have an element with class 'section' from the body of the footer HTML  
          var y = document.getElementsByClassName('section');  
          for(var j = 0; j < y.length; j++)  
          {  
             // if current page equals total pages  
             if (vars[x[2]] == vars[x[1]])  
             {  
                y[j].innerHTML = "I'm a footer only on the last page";  
             }  
          }  
       }  
    </script>  
    </head>  
    <body onload="subst()">  
       <div class="section"></div>  
    </body>  
    </html>  
    

    【讨论】:

    • 谢谢。对于 javascript-dummies:要显示页面/页面样式的页脚,它不会出现在第一页上,请将 if 更改为: if (vars[x[2]] != vars[x[0]]) { var pageNr = vars[x[2]] - 1; var totalPages = vars[x[1]] - 1; y[j].innerHTML = pageNr + "/" + totalPages; }
    • 你好,能告诉我如何只设置第一页吗?
    猜你喜欢
    • 1970-01-01
    • 2018-07-08
    • 2014-06-24
    • 2014-04-08
    • 2017-02-06
    • 1970-01-01
    • 2013-01-11
    • 2020-01-23
    • 1970-01-01
    相关资源
    最近更新 更多