【问题标题】:Webgrid exported to PDF using Rotativa in an MVC applicationWebgrid 在 MVC 应用程序中使用 Rotativa 导出为 PDF
【发布时间】:2016-08-04 16:38:42
【问题描述】:

我正在使用 Rotativa 库将包含 100 条记录的 Webgrid 导出为 PDF。 我能够成功地将数据导出到 PDF,但问题是由于他的网格包含如此多的记录,因此 pdf 在每一页上都有列标题。 因此,列标题与 PDF 每一页中的列内容重叠。 我只想在 pdf 的第一页上设置列标题,而不是在每一页上。

部分视图(_Report.cshtml)如下:

<div id="reportDetailGrid">
        @grid2.GetHtml(
                    tableStyle: "webgrid-table",
             headerStyle: "webgrid-header",
             footerStyle: "webgrid-footer",
             alternatingRowStyle: "webgrid-alternating-row",
             selectedRowStyle: "webgrid-selected-row",
             rowStyle: "webgrid-row-style",
             mode: WebGridPagerModes.All,
            columns: grid2.Columns(
                      grid2.Column("PropertyCode", "PropertyCode", format: @<text>@item.PropertyCode</text>),
                      grid2.Column("TransactionTime", "TransactionTime", format: @<text>@item.TransactionTime</text>),
                      grid2.Column("ConfirmationNo", "ConfirmationNo",format: @<text>@item.ConfirmationNo</text>),
                    grid2.Column("AlertCode", "AlertCode",format: @<text>@item.AlertCode</text>),
                    grid2.Column("ErrorMessage", "ErrorMessage",format: @<text>@item.ErrorMessage</text>)
)
)

    </div>

控制器代码是:

public ActionResult DownloadReportPDF()
    {
      var model = GetReportsViewModelData();
        //Code to get content
        return new Rotativa.PartialViewAsPdf("_Report", model) { FileName = "DigitalDashboardReport.pdf" };
    }

下面是PDF第二页的截图:

而且它发生在 PDF 的每一页上。

任何人都可以帮助我仅在第一页而不是在 PDF 的每一页上设置列标题,或者如果他们以任何其他方式设置要导出为 PDF 的内容的样式。 提前致谢。

【问题讨论】:

  • 谁能帮忙解决这个问题。
  • 我已经通过在局部视图中添加以下样式代码来解决问题:thead { display: table-header-group; } tfoot { 显示:表行组; } tr { page-break-inside:避免; }

标签: asp.net-mvc webgrid rotativa


【解决方案1】:

我已通过在局部视图中添加以下样式代码来解决此问题:

thead { display: table-header-group; } 
tfoot { display: table-row-group; } 
tr { page-break-inside: avoid; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多