【发布时间】:2016-11-14 18:49:47
【问题描述】:
我浏览了很多帖子并尝试了建议的所有内容,但我的 webgrid 流向的页面上没有重复标题。
这是我的代码:
public FileStreamResult ExportCombinedPDF(int ProjectID)
{
List<PipelineDetails> PipeList = new List<PipelineDetails>();
ProjectManager PM = new ProjectManager();
PipeList = PM.GetPipelineList(ProjectID);
//This is the css styling for the webgrid
string webgridstyle = PM.Pipeline_HtmlForExport(ProjectID);
//This is creating the table with other details also being exported
string ProjectHtml = PM.Project_HtmlForExport(ProjectID);
WebGrid grid = new WebGrid(source: PipeList, canPage: false, canSort: false);
string gridHtml = grid.GetHtml(tableStyle: "webGrid",
headerStyle: "webGridHeader",
alternatingRowStyle: "webGridAlt",
columns: grid.Columns(
grid.Column("NodeNumber", "Node Nr."),
grid.Column("Accumulated_Length", "Accumulated Length"),
grid.Column("Elevation", "Elevation"),
grid.Column("Pipe_Outside_Diameter", "Pipe Outside Diameter"),
grid.Column("Wall_Thickness", "Wall Thickness"),
grid.Column("Control_Point_Description", "Control Point Description"),
grid.Column("Control_Point_Size", "Control Point Size"))).ToString();
string exportData = String.Format("<html><body>{0}{1} <br /> {2}</body></html>", "<style>" + webgridstyle + "</style>", ProjectHtml, gridHtml);
var bytes = System.Text.Encoding.UTF8.GetBytes(exportData);
using (var input = new MemoryStream(bytes))
{
var output = new MemoryStream();
var document = new iTextSharp.text.Document(PageSize.A4, 50, 50, 50, 50);
var writer = PdfWriter.GetInstance(document, output);
Font headerFont = FontFactory.GetFont("Verdana", 10);
Font rowfont = FontFactory.GetFont("Verdana", 10);
writer.CloseStream = false;
document.Open();
var xmlWorker = iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
xmlWorker.ParseXHtml(writer, document, input, System.Text.Encoding.UTF8);
document.Close();
output.Position = 0;
return File(output, "application/pdf", "Pipeline_Report.pdf");
//return new FileStreamResult(output, "application/pdf");
}
}
我尝试将repeat-header:yes 添加到我的css,但这不起作用。我还尝试在下面的代码中添加以下内容,但也没有用:
//This was done before the document was opened :
PdfPTable table = new PdfPTable(7);
table.HeaderRows = 2;
//This was done before the document was closed :
document.Add(table);
但如前所述,这也不起作用。我无法想象设置重复标题是如此困难。
否则,下一个选项就是将 WebGrid 设置为在新页面上开始。这甚至可能吗?
如果有任何帮助,我将不胜感激。谢谢。
【问题讨论】:
标签: css asp.net-mvc-5 itext