2013-10-11 22 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); 
} 

但是,唉,這實際上並不正確打破頁。我試着把每個單獨的表格分開,希望能夠做到分頁魔術,但它不會。

我該如何構造這個以允許良好的分頁符?

回答