Hi!
I've been desperately looking for a working example for a week now
I've read that: "
MigraDoc adds page breaks automatically and repeats the table header automatically."
But I haven't found any examples that demonstrate this.
This my currently sample :
Code:
namespace Share.PDF;
using PdfSharpCore.Pdf;
using PdfSharpCore.Drawing;
using MigraDocCore.DocumentObjectModel.Tables;
using MigraDocCore.DocumentObjectModel;
public static class TableMultiPage
{
private static PdfDocument? document;
public static byte[] GetPDF()
{
document = new();
// Create new page
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
//XFont font = new("OpenSans-Regular", 20, XFontStyle.Regular, options);
Document doc = new();
Section sec = doc.AddSection();
sec.PageSetup.TopMargin = Unit.FromCentimeter(5);
sec.PageSetup.BottomMargin = Unit.FromCentimeter(5);
Table table = CreateTableMultiPage( sec);
//PdfDocumentRenderer pr = new();
//pr.PdfDocument.
// Create a renderer and prepare (=layout) the document
MigraDocCore.Rendering.DocumentRenderer docRenderer = new(doc);
docRenderer.PrepareDocument();
// Render the paragraph. You can render tables or shapes the same way.
docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(1), "12cm", table);
MemoryStream PdfStream = new();
document.Save(PdfStream);
return PdfStream.ToArray();
}
private static Table CreateTableMultiPage(Section sec)
{
Table table = new();
table.Borders.Width = 0.75;
table.KeepTogether = false;
table.AddColumn(Unit.FromCentimeter(3));
table.AddColumn(Unit.FromCentimeter(2));
Row row = table.AddRow();
row.Shading.Color = Colors.PaleGoldenrod;
Cell cell = row.Cells[0];
cell.AddParagraph("N.");
cell = row.Cells[1];
cell.AddParagraph("Info");
for (int line = 0; line < 100; ++line)
{
row = table.AddRow();
row.HeadingFormat = true;
row.Borders.Top.Width = 1;
cell = row.Cells[0];
cell.AddParagraph(line.ToString());
cell = row.Cells[1];
cell.Format.Alignment = ParagraphAlignment.Center;
cell.AddParagraph("blablablaa");
}
sec.Add(table);
return table;
}
}
I don't know how to get page breaks
Many thanks in advance !