PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Footer with total pages minus one?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3909
Page 1 of 1

Author:  ibanezmatt93 [ Wed Jan 30, 2019 2:42 pm ]
Post subject:  Footer with total pages minus one?

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

Author:  Thomas Hoevel [ Wed Jan 30, 2019 3:32 pm ]
Post subject:  Re: Footer with total pages minus one?

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.

Author:  ibanezmatt93 [ Wed Jan 30, 2019 4:06 pm ]
Post subject:  Re: Footer with total pages minus one?

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

Author:  TH-Soft [ Wed Jan 30, 2019 8:09 pm ]
Post subject:  Re: Footer with total pages minus one?

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.

Author:  ibanezmatt93 [ Thu Jan 31, 2019 9:06 am ]
Post subject:  Re: Footer with total pages minus one?

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.

Author:  Thomas Hoevel [ Thu Jan 31, 2019 9:12 am ]
Post subject:  Re: Footer with total pages minus one?

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.

Author:  ibanezmatt93 [ Thu Jan 31, 2019 9:18 am ]
Post subject:  Re: Footer with total pages minus one?

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.

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