Hi, i have problem with migradoc. I`am trying to create table by mixing PdfSharp and Migadoc.
My code:
Code:
private void GeneratePdf(ref HttpResponseMessage response, string recordId, Model model)
{
PdfDocument documentpdf = new PdfDocument();
PdfPage page = documentpdf.AddPage();
page.Width = XUnit.FromMillimeter(210);
page.Height = XUnit.FromMillimeter(297);
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.MUH = PdfFontEncoding.Unicode;
XFont fontX = new XFont(SomeFont, 20, XFontStyle.Underline);
Font font = new Font(SomeFont, 11);
Document doc = new Document();
Section section = doc.AddSection();
//logo
AddLogoWithTitle(page, gfx, fontX, SomeDate);
MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
table.Style = "Table";
table.Format.Font = font;
table.Format.Borders.Distance = "0.3cm";
table.Borders.Bottom.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
table.KeepTogether = false;
Column col1a = table.AddColumn("2cm");
col1a.Format.Alignment = ParagraphAlignment.Right;
Column col1aMid = table.AddColumn("2cm");
Column col2a = table.AddColumn("2cm");
col2a.Format.Alignment = ParagraphAlignment.Left;
Column col1b = table.AddColumn("2cm");
col1b.Format.Alignment = ParagraphAlignment.Right;
Column col1bMid = table.AddColumn("2cm");
Column col2b = table.AddColumn("2cm");
col2b.Format.Alignment = ParagraphAlignment.Left;
Row row = table.AddRow();
row.HeadingFormat = true;
//calling it multiple times with other values
CreateSectionPartLabelWith3Merged("someString", model.property, table,row);
DocumentRenderer docRenderer = new DocumentRenderer(doc);
#region Generowanie pliku i renderowanie tabel
docRenderer.PrepareDocument();
docRenderer.RenderObject(gfx, 5, XUnit.FromCentimeter(4), "12cm", table);
}
private void CreateSectionPartLabelWith3Merged(string partLabel, string partValue, MigraDoc.DocumentObjectModel.Tables.Table table, Row row)
{
row = table.AddRow();
row.Cells[0].Format.Font.Bold = true;
row.Cells[1].MergeRight = 4;
row.Cells[0].Format.Font.Size = 11;
row.Cells[0].AddParagraph(partLabel);
row.Cells[1].AddParagraph(partValue);
}
private void AddLogoWithTitle(PdfPage page, XGraphics gfx, XFont fontX, string createDate)
{
XRect rectTitle = new XRect(0, 45, page.Width, 70);
gfx.DrawString("Some text" + createDate, fontX, XBrushes.Black, rectTitle, XStringFormats.Center);
string path = "SomePath"
XImage logoImage = XImage.FromFile(path);
gfx.DrawImage(logoImage, 10, 10, 187, 40);
}
The problem is when i call function to add next row with section and table reach end of page, then my text doesn`t appear on the next page (next page doesn`t exist, just text out of page boundary). I was trying to change table.KeepTogether to false or setting KeepWith to some number but still same problem.