locked
rotativa remove blank space in header excluding the first page RRS feed

  • Question

  • User713522837 posted

    I am using rotativa for pdf generation with a separate view for header and footer. I need a logo and some markup to be displayed only on the first page header and could able to do that by hiding the content, but the height of the header is not getting reduced in the subsequent pages. In the first page, I have the header with logo and markup which is fine. In the second and subsequent pages, there is no logo and markup (which is required), but I am getting the blank space equivalent to the height of logo and markup.

    How to remove the blank space in the second and subsequent pages of the header? Everything else is fine

    string fullName = "fullname";
    string dateOfBirth = "date of birth"
    string customSwitches = string.Format("--header-html  \"{0}\" " +
                            "--header-spacing \"0\" " +
                            "--footer-spacing \"10\" ", Url.Link("GetHeader", new { fullname = fullName, dateofbirth = dateOfBirth}) );

    Header view is as below:

    @inherits System.Web.Mvc.WebViewPage<ViewModels.ServiceablePDFViewModel>    
    <!DOCTYPE HTML>
    <html>
    <head>
        <title></title>
        <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]];
                }
    
                    if (vars[x[0]] != vars[x[2]]) {
                        document.getElementById('container').setAttribute('style', 'display:none').style.height = '0px';
                    }
            }
        </script>
    </head>
    <body onload="subst()">
        <div> Header Title</div>
            <div id="container">
            <p class="logo"><a href="/" title="home page"><img src="/img/logo.png" alt="alternate text" /></a></p>
                <div>Heading</div>
                <div> REF</div>
                <div> Header: @Model.header</div>
                <div> Age: @Model.DateOfBirth </div>
    
                <div>This pdf is (consisting of <span class="topage"></span> pages ) </div>
                <div>Date: </div>
        </div>    
    </body>
    </html>
    string fullName = "fullname";
    string dateOfBirth = "date of birth"
    string customSwitches = string.Format("--header-html  \"{0}\" " +
                            "--header-spacing \"0\" " +
                            "--footer-spacing \"10\" ", Url.Link("GetHeader", new { fullname = fullName, dateofbirth = dateOfBirth}) );
    Wednesday, September 21, 2016 10:32 AM

Answers

  • User713522837 posted

    Resolved by
    if (vars[x[0]] == vars[x[2]]) {
    var el = document.getElementById('container');
    el.style.display = 'block';
    }

    In the div,
    <div style="display:none;height:0"id="container">

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 22, 2016 5:02 PM