Skip to content

How to hide header and footer on first page  #11

@prakash21-hub

Description

@prakash21-hub

@pofider, I am new to jsreport chrome pdf. Currently I am working on .Net Core razor pages showing header and footer for all the pages with the help of chrome class properties header template and footer template.
But now, I have requirement to hide the header and footer on first page, and it should show starting from second page like pagenumber 2 and so on.
please help me how can I disable header and footer on first page of the generated pdf.

Please find my current code below

Controller Method

[MiddlewareFilter(typeof(JsReportPipeline))]
public async Task GeneratePdfForRUN([FromBody] RunModel Pdfdata)
{
try
{

             HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf)
            .Configure((r) => r.Template.Chrome = new Chrome
            {
                DisplayHeaderFooter = true,
                MarginBottom = "2.7cm",
                PrintBackground = false,
                MarginTop = "2.7cm",
                MarginLeft = "1.5cm",
                MarginRight = "1.5cm",
                HeaderTemplate = "<table width='100%'>" +
                     "<tr><td style='padding-left:40em;'><span style='font-size:11px;font-weight:bold;'>" + Pdfdata.Headline + "</span></td>" +
                     "</tr></table>",
                FooterTemplate = "<table><tr> +
                    "<td style='padding-left:50em;'></td>" +
                    "<td style='padding-left:250em;'><p style='font-size:9px;'>Page&nbsp;<span class='pageNumber'></span>&nbsp;of&nbsp;<span class='totalPages'></span></p></td>" +
                    "</tr> </table>"
            }); 
            return View("GeneratePdfForRUN", Pdfdata);
        }
        catch (Exception ex)
        {
            return BadRequest("An exception (" + ex.GetType().Name + ") occurred.<br>" +
                " The action failed with error message:<br> " + ex.Message +
                "<br>The Inner Exception:<br>" +
                ((ex.InnerException != null) ? ex.InnerException.Message : "N/A"));
        }
    }

cshtml

@model PdfPrintService.Models.RunModel
@{
Layout = null;
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("de-DE");
int k = 0;
int ca = 0;
}

<style>

    /* defining explicit font-size solves the scaling issue */
    html, body {
        -webkit-print-color-adjust: exact;
        margin-right: 0px;
        margin-left: 0;
        font-size: 12px;
        font-family: Arial;
    }

    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }

        td span {
            display: inline-block;
        }
            /*styles for label*/

            td span.label {
                font-weight: bold;
                padding-bottom: 2px;
                padding-top: 2px;
                padding-left: 2px;
                vertical-align: top;
            }

            /*styles for value*/

            td span.value {
                padding-bottom: 2px;
                padding-top: 2px;
                vertical-align: top;
            }

            /*styles for separator*/

            td span.separator {
                padding-bottom: 2px;
                padding-top: 2px;
                vertical-align: top;
            }

            td span.headercs {
                text-align:center;
                font-size:large;
                padding:10px;
            }

</style>
@if (Model.PdfData.TLCoverSheetForPDF.Count > 0)
{
    <table style="width:100%; height:80px">
        <tr>
            <td style="width:25%;">
                <span class="headercs">@(
                new Microsoft.AspNetCore.Html.HtmlString(Model.PdfData.TLCoverSheetForPDF[0].CompanyName + " " + Model.PdfData.TLCoverSheetForPDF[0].AdditionalInfo1 + " " + Model.PdfData.TLCoverSheetForPDF[0].AdditionalInfo2)
                )</span>
            </td>
            <td style="width:50%;">
                <span class="headercs">@(
                new Microsoft.AspNetCore.Html.HtmlString(Model.PdfData.TLCoverSheetForPDF[0].DocumentLabelEn + " " + Model.PdfData.TLCoverSheetForPDF[0].DocumentLabelDe)
                )</span>
            </td>
            <td style="width:25%;">
                <span class="headercs">@(
                new Microsoft.AspNetCore.Html.HtmlString(Model.PdfData.TLCoverSheetForPDF[0].HeaderRight)
                )</span>
            </td>
        </tr>
    </table>
    <br />
   
}
<div style='page-break-before: always;'></div>
@* Header Table*@
<table style="width:100%;">
    @*creating table cells dynamically based on the row and column counts*@

    @for (int i = 0; i < Model.PdfData.headerRowCount; i++)
    {
        <tr>
            @for (int j = 0; j < Model.PdfData.headerColumnCount; j++)
            {
                <td style="width:@Model.PdfData.HeaderForPdf[k].ColumnAlignment">

                    <span class="label" style="text-align: left; width:98px "> @(new Microsoft.AspNetCore.Html.HtmlString(Model.PdfData.HeaderForPdf[k].Label)) </span>

                    @if (Model.PdfData.HeaderForPdf[k].Label != null && Model.PdfData.HeaderForPdf[k].Label != "")
                    {
                        <span class="separator">:&nbsp;</span>
                        <span class="value">@(new Microsoft.AspNetCore.Html.HtmlString(Model.PdfData.HeaderForPdf[k].DisplayFreeText))</span>
                    }

                </td>
                k = k + 1;
            }
        </tr>
    }
</table>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions