PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 11:33 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 13, 2015 12:45 am 
Offline

Joined: Wed May 13, 2015 12:32 am
Posts: 2
I am using MigraDoc to create a PDF. As per my requirement, I have to add different headers according to the contents of the page\section. I am able to achieve it by adding new section and defining new header for every section. Till here, it works fine.
In footer, I am showing page numbers using "AddPageField". But I realized that whenever a new section starts, page field reset to 1. Is there any way that footer continues the page count across all sections ?
If I use only one section throughout the document, then page number continues. But in this case, I can not use different headers.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 13, 2015 7:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!
ankitagarg1019 wrote:
Is there any way that footer continues the page count across all sections?
If you do not reset the page count for the new section, the counting just continues. What you want is the default behavior.

So I presume there is an error in your code (which you are not showing).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 14, 2015 12:49 am 
Offline

Joined: Wed May 13, 2015 12:32 am
Posts: 2
Hello Thomas,
Thanks for the reply. No, I am not changing\resetting the page count in new section. But in first section, I added this line.
section.PageSetup.StartingNumber = 2;

Somehow, this line was effecting all the headers. Now, I removed this line and yes, page number continues between sections.
Thanks again. :D


Last edited by ankitagarg1019 on Thu May 14, 2015 4:46 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu May 14, 2015 8:36 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Hi!

Sections inherit the properties from the previous section.

Remove the line "section.PageSetup.StartingNumber = 2;" and page numbering will continue automatically (but section 1 starts with the wrong page number).

I don't know what you have to specify for section 2 to get continuing page numbers if you set a starting value for section 1.
Next week I'll ask Stefan what he thinks about this.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 25, 2015 1:09 pm 
Offline
PDFsharp Guru
User avatar

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

The mystery is solved:
For section one you set the starting number, maybe like this:
Code:
var sec1 = document.LastSection;
sec1.PageSetup = document.DefaultPageSetup.Clone();
sec1.PageSetup.StartingNumber = 17;


For section two you have to assign the PageSetup, but do not set the starting number. Maybe like this:
Code:
var sec2 = document.AddSection();
sec2.PageSetup = document.DefaultPageSetup.Clone();


If you do not set a PageSetup for the second section, then it will inherit the PageSetup from the first section - and it will have the same starting number.
If you set a PageSetup without a starting number for the second section, then everything will be fine and page numbering for section two continues as expected.

A third section would inherit the page setup from the second section, so there is no need to set the page setup.
And with my test, the second section inherited the footer from the first section. So there is no need to duplicate the code that sets header and footer, just set a clean page setup for the second section.

I am sorry that it took me so long to come up with this rather simple solution.
So it is no bug, it's a feature.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 44 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