2013-10-11 20 views
0

我有一个很大的表单,我正在转换成PDF。它的第一个1/6是这样的:MigraDoc:强制嵌入表在逻辑点中断

http://i.imgur.com/y4pO8Th.png

输入字段数然而,变化从1到20个部分,我需要能够智能地使这个文件打破页。我的计划是最初一张一张地绘制表格,并通过获取之前所有表格中的行数来管理Y坐标。这工作,但当我到达分页符时崩溃了,并且我开始需要一些半复杂的逻辑来使其工作,而且这种逻辑会随着添加的每个附加表格变得更加混乱和混乱。

我的第二个计划是重现HTML文档的表结构的PDF,我设法成功地做到......

private void DrawPDF() 
{ 
    Document tDoc = new Document(); 
    MigraDoc.DocumentObjectModel.Style style = tDoc.Styles["Normal"]; 
    style.Font.Name = tPdfFont; 
    style.Font.Size = 10; 
    Section tSec = tDoc.AddSection(); 

    MigraDoc.DocumentObjectModel.Tables.Table masterTable = new MigraDoc.DocumentObjectModel.Tables.Table(); 
    masterTable = tSec.AddTable(); 
    masterTable.Borders.Visible = false; 

    Column leftColumn = masterTable.AddColumn("365pt"); 
    Column spacer = masterTable.AddColumn("10pt"); 
    Column rightColumn = masterTable.AddColumn("365pt"); 

    Row tFS = masterTable.AddRow(); 
    Cell tCell = tFS.Cells[0]; 

    // 
    // Farm Assets Column 
    // 
    { 
     MigraDoc.DocumentObjectModel.Tables.Table tAssetsTable = new MigraDoc.DocumentObjectModel.Tables.Table(); 
     tAssetsTable.Borders.Visible = false; 
     Column tColumn = tAssetsTable.AddColumn("365pt"); 
     tCell.Elements.Add(tAssetsTable); 



     // 
     // Current Farm Assets 
     // 
     for (int i = 0; i < 10; i++) // Drawn 10 times to force it to draw over the 1st page. 
     { 
      Section thisSection = tDoc.AddSection(); 
      Row tAssetsRow = tAssetsTable.AddRow(); 
      Cell tAssetsCell = tAssetsRow.Cells[0]; 

      MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table(); 
      table = thisSection.AddTable(); 
      table.Borders.Width = 0.2; 
      table.Rows.LeftIndent = 0; 

      Column columnData = table.AddColumn("295pt"); 
      columnData.Borders.Left.Visible = false; 
      Column columnValue = table.AddColumn("70pt"); 

      Row rowA = table.AddRow(); 
      rowA.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xa2a2d2")); 
      rowA.Cells[0].AddParagraph("CURRENT FARM ASSETS"); 
      rowA.Cells[1].AddParagraph("$ Value"); 
      rowA.Cells[1].Format.Alignment = ParagraphAlignment.Right; 

      Row row1 = table.AddRow(); 
      row1.Borders.Bottom.Visible = false; 
      row1.Cells[0].AddParagraph("Cash: Savings: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Savings + ") Checking: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Checking + ")"); 
      row1.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.CashTotal); 
      row1.Cells[1].Format.Alignment = ParagraphAlignment.Right; 

      Row row2 = table.AddRow(); 
      row2.Borders.Bottom.Visible = false; 
      row2.Cells[0].AddParagraph("Invest: Time Cret $" + MP.FormFinancialStatement.CurrentStaticAssets.TimeCret + " Other: $" + MP.FormFinancialStatement.CurrentStaticAssets.OtherInvestments + ""); 
      row2.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.InvestTotal); 
      row2.Cells[1].Format.Alignment = ParagraphAlignment.Right; 

      Row row3 = table.AddRow(); 
      row3.Borders.Bottom.Visible = false; 
      row3.Cells[0].AddParagraph("Replacement Account"); 
      row3.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.ReplacementAccount); 
      row3.Cells[1].Format.Alignment = ParagraphAlignment.Right; 

      Row row4 = table.AddRow(); 
      row4.Cells[0].AddParagraph("Accouts and Notes Recievable"); 
      row4.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.AccountsNotesReceivable); 
      row4.Cells[1].Format.Alignment = ParagraphAlignment.Right; 

      MigraDoc.DocumentObjectModel.Tables.Table clone = (MigraDoc.DocumentObjectModel.Tables.Table)table.Clone(); 

      tAssetsCell.Elements.Add(clone); 
     } 
    } 

    MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(tDoc); 
    docRenderer.PrepareDocument(); 
    docRenderer.RenderObject(gfx, 30, 85, "740pt", masterTable); 
} 

但是,唉,这实际上并不正确打破页。我试着把每个单独的表格分开,希望能够做到分页魔术,但它不会。

我该如何构造这个以允许良好的分页符?

回答