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

Page Count
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1366
Page 1 of 1

Author:  henrylar [ Wed Oct 06, 2010 9:10 pm ]
Post subject:  Page Count

Hello All,

1. I simply wish to obtain the page count. I understand I can use AddSectionPagesField(). However, this returns a field object which contains the value I need.

Is there something I'm missing that simply returns the actual value desired, or should I be casting the returned field somehow?

2. Additionally, I am combining PDFs on the fly. Is there a way to combine the counts of both documents into a final page count?

(It's okay if you only have the answer to one of the two questions. Any help is appreciated.)

Thanks in advance!
Henry

Author:  Thomas Hoevel [ Thu Oct 07, 2010 8:57 am ]
Post subject:  Re: Page Count

Hi!
henrylar wrote:
1. I simply wish to obtain the page count. I understand I can use AddSectionPagesField(). However, this returns a field object which contains the value I need.

Is there something I'm missing that simply returns the actual value desired, or should I be casting the returned field somehow?

I don't understand where your problem is.

If you need the page count in the document, then use the field.
After preparing the document for PDF rendering, you can query the page count and use it in your program while creating the PDF pages.
When creating RTF the page count is determined by Word (or any other application using the document) so the field is the only solution here.

Ad hoc I see no case where this is not enough.

Re 2. question: I don't understand what you're trying to achieve.

Author:  henrylar [ Thu Oct 07, 2010 5:07 pm ]
Post subject:  Re: Page Count

I appreciate your help. I'm obviously being a bit dense here because it's alluding me. I have accomplished more difficult things with the library than this and I expect that it's extremely simple to do, yet I haven't been able to find a single example on it.

Do you think you could refer me to, or provide, a small example of querying the page count and returning the value in a variable of type int32, integer, or the like? At the moment, I'm receiving a FIELD OBJECT, that inserts itself into a page at a given location, which is not my desire. I really want a VALUE, not an FIELD OBJECT. If I have to change the code, I can, but, I wanted to touch base with someone who knows much more than I do before I did.

I'm trying to achieve something as simple as "(Page 1 of 5)". When I try, I get the field object displaying on a different line than the text. But, I only want the value of the page count.

Regarding #2: It appears to me that the AddSectionPagesField() method returns a FIELD OBJECT with the count of pages in a single document. So, when I combine two final PDFs into a single PDF document, the page count needs to increase to account for the combined/final output document. I haven't seen an easy way to achieve this updated page count.

(I know there could be other ways to assemble the final document, I'm concerned with the implementation of this specific example.)

REAL WORLD EXAMPLE:
Imagine a coversheet for a fax. Initially AddSectionPagesField() might only add up to 1 for the coversheet itself. However, when you combine documents, memory streams, whatever, then you'll have added more pages to the final/intended document you wish to fax. I have not seen the way to increase this initial page count value.

And, of course, I could be missing something.

Thank you so much for your help!

Henry

Author:  Thomas Hoevel [ Mon Oct 11, 2010 7:23 am ]
Post subject:  Re: Page Count

henrylar wrote:
Regarding #2: It appears to me that the AddSectionPagesField() method returns a FIELD OBJECT with the count of pages in a single document.

The Field object is a MigraDoc feature. When the PDF is being created, all MigraDoc fields will be replaced by literals.

The field was created to allow strings like "Page 1 of 7" or show the total pages on the cover page.
But that'll work only if you create a single MigraDoc document and render that to PDF.

And the text "Page 1 of 7" should show on one line provided there is enough space.

PageCount isn't known yet while creating the MigraDoc document. You can get the integer value when the document is finalized and prepared.

After combining several PDF files with PDFsharp, you can use PDFsharp to draw the total page count onto the title page (leave the space empty while creating the page with MigraDoc).
Both applications (Creator and Combiner) must use the same location.

Author:  henrylar [ Mon Oct 11, 2010 5:13 pm ]
Post subject:  Re: Page Count

Hello Thomas,

I appreciate your response. However, outside of you creating one, is there an example of this anywhere that you can think of? Like I said before, it seems to be alluding me.

Many thanks,
Henry

Author:  Thomas Hoevel [ Tue Oct 12, 2010 8:51 am ]
Post subject:  Re: Page Count

henrylar wrote:
is there an example of this anywhere that you can think of?

I'm not sure what you're looking for.

If you want to add page numbers using MigraDoc, do it like this:
Code:
// Create footer
Paragraph paragraphOne = section.Footers.Primary.AddParagraph();
paragraphOne.AddText("Seite ");
paragraphOne.AddPageField();
paragraphOne.AddText("/");
paragraphOne.AddNumPagesField();
paragraph.Style = "Style1";


Page count must not start at 1:
Code:
section.PageSetup.StartingNumber = 1;


So page numbering in the first document can start at 2 (reserving 1 for the cover page).
If the first document has 8 pages, second document can start at page 9.


Here is a snippet that calls RenderPage to create the PDF file page by page:
viewtopic.php?p=1735#p1735
This way you get your fingers on the PdfPage objects; thus you can modify the pages right when they are created; you can even store the pages in a list and when the document is done, you can still modify the pages (to add pages numbers and or total page count).

It should work to begin with an empty cover page, then create the other documents and finally create the cover page with the total page number and references to the following documents at pages 2 and 9 respectively.

Author:  henrylar [ Tue Oct 12, 2010 6:14 pm ]
Post subject:  Re: Page Count

Hi Thomas,

I hope you can appreciate that I, like many, like PDFSharp but it represents a paradigm change. Thank you for the simple example you provided. I was wondering if there was an example of your elaboration:

"After combining several PDF files with PDFsharp, you can use PDFsharp to draw the total page count onto the title page (leave the space empty while creating the page with MigraDoc).
Both applications (Creator and Combiner) must use the same location."

Being so new to the SDK, this seems a bit tricky.

Vielen Dank (für alles)!
Henry

Author:  Thomas Hoevel [ Wed Oct 13, 2010 7:31 am ]
Post subject:  Re: Page Count

henrylar wrote:
"After combining several PDF files with PDFsharp, you can use PDFsharp to draw the total page count onto the title page (leave the space empty while creating the page with MigraDoc).
Both applications (Creator and Combiner) must use the same location."

The TwoPagesOnSample shows how to combine PDF files and how to draw text on the pages.
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

Author:  henrylar [ Wed Oct 13, 2010 11:15 pm ]
Post subject:  Re: Page Count

Thanks Thomas. I will make this work.

I appreciate it,
Henry

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