PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

FormattedDocument.PageCount wrong?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=854
Page 1 of 1

Author:  mikesowerbutts [ Fri Aug 28, 2009 3:10 pm ]
Post subject:  FormattedDocument.PageCount wrong?

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?

Author:  Thomas Hoevel [ Mon Aug 31, 2009 7:09 am ]
Post subject:  Re: FormattedDocument.PageCount wrong?

Hi!
mikesowerbutts wrote:
I am a little confused at the behavoiur of this - can anyone shed some light?

Is PageCount strange or are there some "invisible" items (e. g. empty paragraphs) on the last page of your document?

Author:  mikesowerbutts [ Tue Sep 01, 2009 8:22 am ]
Post subject:  Re: FormattedDocument.PageCount wrong?

No there shouldnt be any empty items causing the additional page to appear in the document. If i add a DocumentObject, I always use it. Should I be using come kind of container?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/