Using Rotativa to generate PDF From a view when the page breaks data continue on the header of the second page disregarding CSS

user4135501

I have tried many answers and have came up with the conclusion that there were no answer even from the developers themselves, I have an index page that gets created by a complex module, the view receives the module with ActionAsPdf and produce the PDF except when page breaks the table continue on the next page overwriting records on top of the table headers.

public ActionResult PrintRoster(Guid id)
    {
        string footer = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";

        return new ActionAsPdf("RosterPDF", 
                            new { id = id }) { FileName = "ClassRoster.pdf",
                                                PageSize = Rotativa.Options.Size.A4,
                                                PageOrientation = Rotativa.Options.Orientation.Portrait,
                                                MinimumFontSize = 16,
                                                PageMargins = {Top = 15, Bottom = 22},
                                                PageHeight = 40,
                                                CustomSwitches = footer
                            };
    }

the RosterPDF gets created then it produce the PDF in question

@model Training.ViewModels.RosterViewModel
@using Training.UtilModels
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/trstyle.css" rel="stylesheet" />
<link href="~/Content/themes/base/css" rel="stylesheet" />
<link href="~/Content/Print.css" rel="stylesheet" media="print" />
<title></title>
</head>
<body>  
<h1 class="text-center">Class Attendance</h1>
<hr>
<div class="row">
    <div class="col-sm-4 text-justify"> <strong> Class Name: </strong> @Model.MClass.ClassName </div>
    <div class="col-sm-4 text-justify"> <strong>Instructor: </strong> @Model.MClass.Instructors.FirstOrDefault().FullName</div>
</div>
<div class="row">
    <div class="text-justify col-sm-4"> <strong> Section Number: </strong> @Model.MClass.SectionNumber </div>
    <div class="col-sm-4 text-justify"> <strong>Term: </strong> @Model.MClass.Term.TermName</div>
</div>
<div class="row">
    <div class="text-justify col-sm-4"> <strong> Location: </strong> @Model.MClass.TLocation.LocationName </div>
    <div class="col-sm-4 text-justify"> <strong>Year: </strong> @Model.MClass.ClassStartDate.Year</div>
</div>
<hr>

<table id="Events" class="table table-bordered table-striped page-breaker">

    <thead>
        <tr>
            <th>Name</th>
            <th>Payroll<br /> Number</th>
            @for (int i = 1; i <= Model.MClass.Course.NoDays; i++)
            {
                <th>@BusinessDay.AddWorkDays(Model.MClass.ClassStartDate, i).AddDays(-1).ToShortDateString()</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var x in Model.ClassAttendances)
        {
            <tr>
                <td><strong>@x.StudentName</strong></td>
                <td>@x.PayrollNo</td>
                @for (int i = 0; i < Model.MClass.Course.NoDays; i++)
                {
                    <td>@(x.AttendanceCodeId.ElementAt(i) != 0 ? x.AttendnaceCodes.Where(t => t.Value == x.AttendanceCodeId.ElementAt(i).ToString()).Select(t => t.Text).FirstOrDefault() : "")</td>
                }
            </tr>
        }
    </tbody>
    <tfoot style="page-break-after: always;">
        <tr>
            <td colspan="10" class="page-breaker">
                <strong>STUDENTS: Please make any corrections to your name or number directly on this form.</strong>
            </td>
        </tr>
    </tfoot>
</table>

the out put looks as follow

The output

Stephen Zeng

I fixed a similar issue by adding this in css:

tr {
    page-break-inside: avoid;
}

Hope it works for you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using Rotativa to generate PDF From a view when the page breaks data continue on the header of the second page disregarding CSS

From Dev

How to display page breaks in PDF generated by Rotativa

From Dev

Rotativa breaks the HTML when there is more than one page

From Dev

fpdf table rows breaks from second page

From Dev

Watermark in Pdf using css or Rotativa (PDF generater)

From Dev

WebGL view breaks page

From Dev

WebGL view breaks page

From Dev

How to get page number on dompdf PDF when using "view"

From Dev

css pdf page - header overlapping with content

From Dev

Why does Rotativa always generate my login page? Why is it slow?

From Dev

Split the Header page into to images using CSS

From Dev

HTML/CSS: empty page + only header page when printing table

From Dev

page breaks and css - how to skip last page?

From Dev

page breaks and css - how to skip last page?

From Dev

SignalR - How to PUSH data from one page to second page?

From Dev

PDF Page view tracking

From Dev

Have the header row for the table starting from the second page

From Dev

css to fix the header of the page

From Dev

Table headers overlapping content on second page when converting to PDF with wkhtmltopdf

From Dev

How to continue field output on a second page?

From Dev

PDF is blank page when using CGPDFContextCreateWithURL

From Dev

Page.Header.Controls.Add(css) for MVC razor view

From Dev

how to change code when you view the page for second time

From Dev

Ionic view not updating page when opened second time

From Dev

Add a Header to Every Page in a PDF?

From Dev

How to identify page breaks using python-docx from docx

From Dev

Ruby Prawn PDF Prevent Header Space From Populating Next Page

From Dev

Ruby Prawn PDF Prevent Header Space From Populating Next Page

From Dev

How to generate pdf from a libreoffice calc sheet fitting the page width?

Related Related

  1. 1

    Using Rotativa to generate PDF From a view when the page breaks data continue on the header of the second page disregarding CSS

  2. 2

    How to display page breaks in PDF generated by Rotativa

  3. 3

    Rotativa breaks the HTML when there is more than one page

  4. 4

    fpdf table rows breaks from second page

  5. 5

    Watermark in Pdf using css or Rotativa (PDF generater)

  6. 6

    WebGL view breaks page

  7. 7

    WebGL view breaks page

  8. 8

    How to get page number on dompdf PDF when using "view"

  9. 9

    css pdf page - header overlapping with content

  10. 10

    Why does Rotativa always generate my login page? Why is it slow?

  11. 11

    Split the Header page into to images using CSS

  12. 12

    HTML/CSS: empty page + only header page when printing table

  13. 13

    page breaks and css - how to skip last page?

  14. 14

    page breaks and css - how to skip last page?

  15. 15

    SignalR - How to PUSH data from one page to second page?

  16. 16

    PDF Page view tracking

  17. 17

    Have the header row for the table starting from the second page

  18. 18

    css to fix the header of the page

  19. 19

    Table headers overlapping content on second page when converting to PDF with wkhtmltopdf

  20. 20

    How to continue field output on a second page?

  21. 21

    PDF is blank page when using CGPDFContextCreateWithURL

  22. 22

    Page.Header.Controls.Add(css) for MVC razor view

  23. 23

    how to change code when you view the page for second time

  24. 24

    Ionic view not updating page when opened second time

  25. 25

    Add a Header to Every Page in a PDF?

  26. 26

    How to identify page breaks using python-docx from docx

  27. 27

    Ruby Prawn PDF Prevent Header Space From Populating Next Page

  28. 28

    Ruby Prawn PDF Prevent Header Space From Populating Next Page

  29. 29

    How to generate pdf from a libreoffice calc sheet fitting the page width?

HotTag

Archive