我已经浏览了很多帖子并尝试了所有建议的内容,但是我的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设置为在新页面上启动。这甚至可能吗?
我将不胜感激任何帮助。谢谢。
答案 0 :(得分:0)
所以我能够使用分页功能。所以想到这也给了我一个我想要的结果,我会发布作为答案。
我通过添加PageBreak改变了我的exportData字符串:
string exportData = String.Format("<html><body>{0}{1} <p style='page-break-after:always;'></p> {2}</body></html>", "<style>" + webgridstyle + "</style>", ProjectHtml, gridHtml);
答案 1 :(得分:0)