首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当页面中断时,使用Rotativa从视图生成PDF,数据继续在第二个页面的标题上继续,而不考虑CSS。

当页面中断时,使用Rotativa从视图生成PDF,数据继续在第二个页面的标题上继续,而不考虑CSS。
EN

Stack Overflow用户
提问于 2015-10-26 22:18:06
回答 1查看 7.6K关注 0票数 1

我尝试了许多答案,并得出结论,即使开发人员自己也没有答案,我有一个由复杂模块创建的索引页,视图接收带有ActionAsPdf的模块并生成PDF,除非页面在下一页上继续覆盖表标题顶部的记录。

代码语言:javascript
复制
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
                            };
    }

创建RosterPDF,然后生成有关的PDF。

代码语言:javascript
复制
@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>

输出如下所示

输出量

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-21 08:56:19

我在css中添加了以下内容,从而解决了类似的问题:

代码语言:javascript
复制
tr {
    page-break-inside: avoid;
}

希望它对你有用。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33356609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档