PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 13, 2024 10:58 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 28, 2009 3:10 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 31, 2009 7:09 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
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?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 01, 2009 8:22 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group