【问题标题】:All pages with header excluding first page - RotativaPDF除首页外的所有带有页眉的页面 - RotativaPDF
【发布时间】:2014-06-23 16:27:59
【问题描述】:

我正在尝试使用 RotativaPDF 创建一个可导出/可打印的页面,其中这些页面必须有一小部分包含来自客户的一些数据、包含客户信用和付款的表格,并且每个页面都必须有页脚和页眉(不包括第一页)。

我的控制器的操作:

public ActionResult ExportToPDF()
    {
        var customer= new Customer();
        var customerData = string.Format("Name: {0} | Client Nr.: {1}", customer.Name, customer.CardNumber);
        return new ActionAsPdf("ExportPDF")
        {
            CustomSwitches = "--footer-right \"[page]/[topage]\" " +
                             "--footer-left \"Emission date: [date]\" " +
                             "--header-right \""+ customerData + "\" " +
                             "--header-left \"Customer Data\" " +
                             "--footer-font-size \"11\" " +
                             "--header-font-size \"11\" " +
                             "--footer-spacing \"10\" " +
                             "--header-spacing \"20\""
        };
    }

注意:我定义的 CustomSwitches 就像在 this link 上描述的那样。

使用我的代码,所有页面都会显示一个标题。我应该如何在首页显示页眉?

预期结果:

【问题讨论】:

标签: jquery html asp.net-mvc-4 rotativa


【解决方案1】:

找到答案@Hide Footer on first page

知道它的回复很晚,但可能会帮助某人

所以要在我使用的第一页中隐藏标题

<!DOCTYPE html>
<html>
   <head>
      <script>
         function subst() {
             var vars = {};
              // explore 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 first page  
                 if (vars[x[2]] == 1) {
                     y[j].innerHTML = "";
                     document.getElementsByClassName('section').style.display = 'none';
                 }
             } 
         }
      </script>
   </head>
   <body style="border: 0; margin: 0;" onload="subst()">
      <table style="width: 100%;" border="0"  class="section">
         <tr>
            <td>My header</td>
         </tr>
      </table>
   </body>
</html>

【讨论】:

    【解决方案2】:

    我在文档中看到了以下可能有用的内容。也许你可以做一些逻辑来根据页码隐藏第一页页眉/页脚

    页眉和页脚也可以随 HTML 文档一起提供。作为一个 示例一可以指定 --header-html header.html,并使用 header.html 中的以下内容:

    <html>
        <head>
            <script>
                function subst() {
                    var vars={};
                    var x=document.location.search.substring(1).split('&');
    
                    for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
    
                    var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
    
                    for(var i in x) {
                        var y = document.getElementsByClassName(x[i]);
                        for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                    }
                }
            </script>
        </head>
        <body style="border:0; margin: 0;" onload="subst()">
            <table style="border-bottom: 1px solid black; width: 100%">
              <tr>
                <td class="section"></td>
                <td style="text-align:right">
                  Page <span class="page"></span> of <span class="topage"></span>
                </td>
              </tr>
            </table>
        </body>
    </html>
    

    【讨论】:

    • "var x" 是重复的,不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    相关资源
    最近更新 更多