Hi,
I am trying to create a rendering function to render MigraDoc documents but add the PDFSharp PdfDocument pages as required - I realise that MigraDoc tables will automatically split onto as many pages as required, but wont add pages to the PdfDocument they will eventually be rendered to.
I am currently trying to use:
Code:
public void renderPgs()
{
DocumentRenderer renderer = new DocumentRenderer(document);
renderer.PrepareDocument();
for (int i = 1; i <= renderer.FormattedDocument.PageCount; i++)
{
try
{
renderer.RenderPage(gfx, i);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
if (i > pdfDocument.PageCount)
{
page = pdfDocument.AddPage();
page.Size = PageSize.A4;
gfx = XGraphics.FromPdfPage(page);
gfx.MUH = PdfFontEncoding.Unicode;
gfx.MFEH = PdfFontEmbedding.Always;
}
}
}
but for some reason when a document is rendered to one page, it returns the renderer.FormattedDocument.PageCount as 2? Also, when I have a document that will be two pages long, renderer.FormattedDocument.PageCount is still 2? rather than say 3 which would mean I could offset it by one.
The problem I am facing is that I have tables being populated by data which can be any length, so they potentially will take 2 - 3 pages rather than the initial 1 page I add to the PdfDocument object, so I need to work out the number of pages required at render time, and the fact the PageCount property is being strange means I frequently get an additional blank page at the end of my document!
I am a little confused at the behavoiur of this - can anyone shed some light?