PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Aug 19, 2019 9:06 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Jan 30, 2019 2:42 pm 
Offline

Joined: Wed Jan 30, 2019 2:31 pm
Posts: 4
Hi guys...

I'm evaluating MigraDoc, to see if it's a viable technology change from the tech the company I work for are already using - so far it's fairly promising.

Currently using the GDI+ based empira Software NuGet Package (v1.32.4334) .

I have some code to add a footer to a section - my requirement is that I need to use the "AddPageField()" and "AddNumPagesField()" but 1 lower than the actual page:

A better explained example would be, I have a cover page which has it's own footer - the page count does not start from the cover page.

The next page that's added has a new footer (the one below), where on the right it displays Page 1 of 1 - if we had a document where there is only the cover page and this next page I have described.

Code:
Paragraph paragraph = sec.Footers.Primary.AddParagraph();
      paragraph.AddFormattedText(label, font);
      var topBorder = new Border()
      {
           Color = borderColour,
           Width = 0.5,
           Style = BorderStyle.Single
       };
       paragraph.Format.Font = font;
       paragraph.Format.Borders.Top = topBorder;
       paragraph.Format.Borders.DistanceFromTop = 1.5;
       paragraph.Format.Alignment = ParagraphAlignment.Left;
       paragraph.Format.LeftIndent = Unit.FromMillimeter(-15.7);
       paragraph.AddTab();
       paragraph.Format.AddTabStop(Unit.FromMillimeter(173), TabAlignment.Right);
       paragraph.AddFormattedText("Page ");
       paragraph.AddPageField();
       paragraph.AddFormattedText(" of ");
       paragraph.AddNumPagesField();


Does anybody have a suggestion for me, as I can't quite work out how to do it?

Thank you all in advance,
Matt


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 30, 2019 3:32 pm 
Offline
PDFsharp Guru
User avatar

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

A MigraDoc document can have multiple sections.

Make a section for the cover page - this is page 1 of 1.
Then start a new section and start with page 1 again.
If you have 4 pages including cover page, then the last page will be page 3 of 3.
AIUI this is exactly what you want.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 30, 2019 4:06 pm 
Offline

Joined: Wed Jan 30, 2019 2:31 pm
Posts: 4
Thomas Hoevel wrote:
Hi!

A MigraDoc document can have multiple sections.

Make a section for the cover page - this is page 1 of 1.
Then start a new section and start with page 1 again.
If you have 4 pages including cover page, then the last page will be page 3 of 3.
AIUI this is exactly what you want.


Hi Thomas, thanks for the fast reply.

This is exactly what I currently do, actually. My cover page is one section, and my next page is a new section entirely. So that didn't seem quite right, unless I've missed something.

I have realised that I could use the code:

Code:
sec.PageSetup.StartingNumber = 0;


on my cover page to achieve the effect of page 1 being my second page. However, the numpage value remains the same at '2', am I missing something?

Thanks,
Matt


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 30, 2019 8:09 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 479
Location: CCAA
Hi!

For the second section you need this (for a clean solution):
Code:
sec.PageSetup.StartingNumber = 1;


And you probably have to use "AddSectionPagesField" instead of "AddNumPagesField" to get the correct section total.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 9:06 am 
Offline

Joined: Wed Jan 30, 2019 2:31 pm
Posts: 4
Thanks again - I'm not sure that will ultimately solve my future problems - for what I previously explained, it does.

However, as the document I need to build is a dummy of some of my company's current reports, that solution won't work.

These have multiple sections, with numerous orientation changes, and differing overall section properties for portrait and landscape orientations.

This means using the 'AddSectionPagesField()' will only give me a page count of the current section, and not the total pages of the document, minus one page. Thus, I end up with page 1 of 1 in my first section, but as I change orientation, and ultimately need to use different section properties - this then becomes 'Page 2 of 1'.

I am determined to continue investigating MigraDoc as a potential solution, so at present will have to leave this is a minor issue at present.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 9:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2956
Location: Cologne, Germany
MigraDoc uses PDFsharp to create the PDF.

For special needs with the PDF file you can use MigraDoc to create a document without page numbers and finally add the page numbers using PDFsharp.
Not nice, but you can do anything this way.

The MigraDoc fields should also work when creating RTF (for MS Word), but they cannot provide features that go beyond the RTF/Word functionality.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 9:18 am 
Offline

Joined: Wed Jan 30, 2019 2:31 pm
Posts: 4
Thomas Hoevel wrote:
The MigraDoc fields should also work when creating RTF (for MS Word), but they cannot provide features that go beyond the RTF/Word functionality.


Thanks, yes - I was utilising a combination of PDFSharp and MigraDoc previously, but was curious to see exactly how much I could entirely with MigraDoc as there is some more complicated functionality I have to work with (I have already got this working), and is much easier to handle using MigraDoc and the final rendering alone, rather than the combination of MigraDoc and PDFSharp.

I expect that it can't do more than what MS word can do, but you can edit field codes in Word (and in OpenXML - although this is not particularly pleasant in code format) to read {NUMPAGES - 1}, and {PAGE - 1} which achieves exactly what I'm trying to achieve.

That is more like what I'm trying to achieve, if that makes more sense than my previous explanations?

I realise I probably should have just asked that in the first place to make my issue a little clearer.

Matt.


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

All times are UTC


Who is online

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