PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 6:16 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Page Count
PostPosted: Wed Oct 06, 2010 9:10 pm 
Offline

Joined: Tue Aug 31, 2010 6:16 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Thu Oct 07, 2010 8:57 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Thu Oct 07, 2010 5:07 pm 
Offline

Joined: Tue Aug 31, 2010 6:16 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Mon Oct 11, 2010 7:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Mon Oct 11, 2010 5:13 pm 
Offline

Joined: Tue Aug 31, 2010 6:16 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Tue Oct 12, 2010 8:51 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Tue Oct 12, 2010 6:14 pm 
Offline

Joined: Tue Aug 31, 2010 6:16 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Wed Oct 13, 2010 7:31 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Page Count
PostPosted: Wed Oct 13, 2010 11:15 pm 
Offline

Joined: Tue Aug 31, 2010 6:16 pm
Posts: 10
Thanks Thomas. I will make this work.

I appreciate it,
Henry


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 53 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