繁体   English   中英

在第一页上隐藏页脚

[英]Hide Footer on first page

是否可以隐藏特定页面的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]"
                    }
                }
            }
        };

该API似乎不支持此功能。 但是,我在这里找到了WKHTMLTOPDF的解决方法,可能对您有用。

将以下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>  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM