PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 11:31 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: Tue Nov 17, 2009 10:22 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I have a function to render my pages, I call this function each time I have finished creating a "Page" a page may potentially overflow onto a 2nd or 3rd etc. page if the content is too long.

Currently I am using:
Code:
public void RenderPgs()
        {
            try
            {
                Renderer = new DocumentRenderer(CommonData.Instance.Document);
                Renderer.PrepareDocument();
                try
                {
                    Renderer.RenderPage(Gfx, CommonData.Instance.PdfDocument.PageCount);
                    Gfx.Dispose();
                }
                catch
                {
                }
                int _pgCnt = CommonData.Instance.PdfDocument.PageCount;
                if (CommonData.Instance.PdfDocument.PageCount < Renderer.FormattedDocument.PageCount)
                {
                    while (CommonData.Instance.PdfDocument.PageCount < Renderer.FormattedDocument.PageCount)
                    {
                        try
                        {
                            string _title = Page.Tag.ToString();
                            if (Page.Orientation == PageOrientation.Landscape)
                            {
                                AddPage(PageOrientation.Landscape);
                            }
                            else
                            {
                                AddPage();
                            }
                            SetupHeaderFooter(_title + "overflow");
                            //break;
                        }
                        catch
                        {

                        }
                    }
                    if (_pgCnt < CommonData.Instance.PdfDocument.PageCount)
                    {
                        for (int i = _pgCnt; i < CommonData.Instance.PdfDocument.PageCount; i++)
                        {
                            Renderer = new DocumentRenderer(CommonData.Instance.Document);
                            Renderer.PrepareDocument();
                            Renderer.RenderPage(Gfx, i + 1);
                            Gfx.Dispose();
                        }
                    }
                }
            }
            catch
            {

            }
        }

As you may notice I am essentially rendering a page at the top, but lower down in the if condition, I check if the MigraDoc Document contains more pages than the PdfDocument, and then loop to recursivly add pages, I then loop through the added pages (once they have all been added) and render them each in turn. I am having a problem, becuase I need the page header on the "additional" pages to be correct, rather than the page number of the previous page. the function SetupHeaderFooter() should technically do this, but even when I set the parameter to something like "testing123" so it will replace the test in the page header on the "additional" page it is still using the text from the header on the previous "normal" page? I thought calling Renderer.PrepareDocument() may kind of refresh it, so it would pick up the new header, but it doesnt seem to!

Any ideas?

I am using v1.2

Also, I have build up a large number of functions which work with v1.2, will upgrading to v1.3 cause these to break? i.e. is v1.3 totally backwards compatible?

thanks

Mike


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 17, 2009 3:23 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi, Mike!

MigraDoc allows to set a specific header for the first page and the "normal" header for the following pages.

Set
Code:
section.PageSetup.DifferentFirstPageHeaderFooter = true;

and then set
Code:
section.Headers.FirstPage = ... // Header for first page
section.Headers.Primary = ...// Header for other pages


MigraDoc can insert the correct page number for you.
Use Paragraph's
Code:
AddPageField()

for the page number.

Set
Code:
section.PageSetup.StartingNumber

if you want a number different of 1 for your starting page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 17, 2009 4:24 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
HI Thomas,

I have come accross the dirrerent header on first page thing before, but this isnt the first page, it happens to be the last two pages (technically 1 page which overflows onto two) but it could be any page in any place in the PDF, so im not sure that is applicable?

I am looking to be able to render a page with the header/footer i set in my main code, then any overflow pages (which are added specifically in the RenderPgs() function) should set their own header because I call my function SetupHeaderFooter() - but it is as if the changes to the MigraDoc Document are being ignored - is this becuase I have already called Renderer.PrepareDocument()? I make a 2nd call to this function after I have called SetupHeaderFooter(), so I cant really see why it isnt working?

Mike


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: No registered users and 403 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group