Rotativa Header display error in some pages

0

This is the header

This is the error tat appears instead the header in some pages

I've think this problem appears only for a pdf generated with several pages because I never caught with this error until I generate a big pdf.

In the command console I can read the whole error message:

HT T P Error 502.3 - Bad Gateway The specified CGI application encountered an error and the server terminated the process. Error Code 0x80072efd Requested UR https://localhost:44384/HeadersFootersPDF/HeaderPartidas?page=3

This is the controller:

public async Task<IActionResult> MostrarTodo(int Anio)
    {
        var cuentas = await db.PartidaDiario.Where(c=> c.AnioFiscal == Anio).Include(c => c.CuentasPartida).ToListAsync();
        string cusomtSwitches = string.Format("--page-offset 0 --header-right \"PƔgina:\t\t\t\t\t\t\t\t\t\t\t\t [page]\" " +
            "--header-font-size 7 " +
            "--print-media-type " +
            "--allow {0} " +
            "--header-html {0} --margin-top 30 --header-spacing 20",
        Url.Action("HeaderPartidas", "HeadersFootersPDF", new { area = "" }, "https"));

        return new ViewAsPdf("Detalles", cuentas)
        {
            FileName = "PARTIDAS-" + Anio + ".pdf",
            CustomSwitches = cusomtSwitches
        };
    }

This is the header:

    @{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Header</title>
</head>
<body style="position:absolute !important; margin-top: 85px !important; width:100% !important; text-align:center;">
    <div style="font-size: 20px; text-align:center; font-family: Arial; font-weight:bold;">
        <br /><br /><br />
        <label>W ASOCIADOS, S.A. DE C.V.</label><br />
        <label>Libro Diario</label>
    </div>
    <hr style="border: 2px solid #0076AE; " />
    <br />
</body>
</html>

This is the view:

@model IEnumerable<PartidaDiario>
@{
    ViewData["Title"] = "Detalles";
    Layout = null;
}

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>LibroMayorGenerado</title>
    <style>
        table, th, td {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
    @foreach (var partida in Model)
    {
        string page_break = "";
        if (partida != Model.Last())
        {
            page_break = "page-break-after: always;";
        }

        <div style="">
            <table style="@page_break margin-top:15px; width:100%;">
                <tr>
                    <th colspan="5" style="text-align:left; border-top:1px solid; border-left:1px solid; border-right:1px solid;">
                        <label>Fecha:  @partida.Fecha</label>
                        <label style="margin-left: 60px;">Numero: @partida.Id</label>
                        <label style="margin-left: 130px;">Tp: Diario</label>
                    </th>
                </tr>
                <tr>
                    <th colspan="1" style="padding-top:15px; text-align:left; border-bottom:1px solid; border-left:1px solid; ">Codigo</th>
                    <th colspan="1" style="padding-top:15px; text-align:left; border-bottom:1px solid;">Descripción</th>
                    <th colspan="1" style="padding-top:15px; text-align:left; border-bottom:1px solid;">Cheque</th>
                    <th colspan="1" style="padding-top:15px; text-align:left; border-bottom:1px solid;">Debe</th>
                    <th colspan="1" style="padding-top:15px; text-align:left; border-bottom:1px solid; border-right:1px solid;">Haber</th>
                </tr>

                @{
                    decimal total_debe = 0;
                    decimal total_haber = 0;
                }

                @foreach (var cuenta in partida.CuentasPartida)
                {
                    total_debe += (decimal)cuenta.Debe;
                    total_haber += (decimal)cuenta.Haber;

                    <tr>
                        <td colspan="1" style="padding-top:15px; text-align:left; ">@cuenta.CodigoCuenta</td>
                        <td colspan="1" style="padding-top:15px; text-align:left; ">@cuenta.NombreCuenta</td>
                        <td colspan="1" style="padding-top:15px; text-align:left; "></td>
                        <td colspan="1" style="padding-top:15px; text-align:left; ">$ @String.Format("{0,15:#,##0.00 ;(#,##0.00);}", cuenta.Debe)</td>
                        <td colspan="1" style="padding-top:15px; text-align:left; ">$ @String.Format("{0,15:#,##0.00 ;(#,##0.00);}", cuenta.Haber)</td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top:15px; text-align:left; border-bottom:1px solid;">@cuenta.Descripcion</td>
                    </tr>
                }
                <tr>
                    <td colspan="1" style="padding-top:15px; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:1px solid; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:1px solid; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:1px solid; text-align:left; "></td>
                </tr>
                <tr>
                    <td colspan="1" style="padding-top:15px; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; text-align:left; "></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:2px solid; text-align:left; "><strong>Total partida:</strong></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:2px solid; text-align:left; "><strong>$ @String.Format("{0,15:#,##0.00 ;(#,##0.00);}", total_debe)</strong></td>
                    <td colspan="1" style="padding-top:15px; border-bottom:2px solid; text-align:left; "><strong>$ @String.Format("{0,15:#,##0.00 ;(#,##0.00);}", total_haber)</strong></td>
                </tr>
            </table>
        </div>
    }
</body>
</html>

I really appreciate some help, I'm new with asp.net core and using this framework.

pdf
asp.net-core
pdf-generation
wkhtmltopdf
rotativa
asked on Stack Overflow Dec 11, 2019 by Juan Erroa • edited Dec 11, 2019 by Juan Erroa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0