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

MigraDoc: Printing multiple Documents and Page Numbers
https://forum.pdfsharp.net/viewtopic.php?f=2&t=457
Page 1 of 1

Author:  Thomas [ Wed Aug 27, 2008 12:39 pm ]
Post subject:  MigraDoc: Printing multiple Documents and Page Numbers

Hey guys.

I successfully created my single invoice document by following your sample. I also included page numbers, which is a nice feature itself.

But now I am trying to mass generate invoices, which means I want to generate each single invoice as before, and add it to a "container" document which includes all invoices.

This works fine:

Code:
Document document = new Document();

OrderCollection orders = ShopServiceManager.Orders().GetOrdersByCustomer(34);
foreach (var order in orders)
{
    BL.Documents.Invoice invoice = new BL.Documents.Invoice();
    invoice.DocumentCreator = new InvoiceDocument();
    invoice.Order = order;
    invoice.Print(false);
    document.Add(invoice.Document.LastSection.Clone());
}

PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();


The print method sets the property Document of the invoice object to the internally new generated MigraDoc Document. By adding the LastSection I can add the single document to the container doc and print this container document at the and of the game.

This all works. The problem: the page numbers are counted over all single invoice documents within the container doc. For example, if I am printing 6 invoices which are all containing one single page, I should get a result like 6 times "Page 1/1". Instead of that I get "Page 1/6", "Page 2/6" and so on - because the used AddNumPagesField() seems to be counted over all documents (sections).

I was trying to render each single invoice within the loop and add the final rendered result to the container document, but with no success.

I would be very glad if anyone could assist.

Thanks in advance!

Author:  Thomas Hoevel [ Wed Aug 27, 2008 1:06 pm ]
Post subject: 

Hi!

How about using AddSectionPagesField() instead?
Don't forget to set section.PageSetup.StartingNumber ...

Author:  Thomas [ Wed Aug 27, 2008 1:35 pm ]
Post subject: 

Hi Thomas,

thanks for your fast response. With AddSectionPagesField() I get the absolute count of pages in the section, but how do I receive the current page number?

P.s.: Is there a documentation available anywhere? It's really a great library, but also a hard trial and error game :(

Author:  Thomas Hoevel [ Wed Aug 27, 2008 1:52 pm ]
Post subject: 

No change for page number (that's why you have to set the starting number).

Re: documentation:
I press F12 and look what's there.
Press F12 on AddNumPagesField and you'll find AddSectionPagesField.
I knew there was a way to set the starting page of a section; since I didn't find it in Section, I looked in PageSetup.

Apart from Intellisense there are no documents worth mentioning.
The samples are a good source of information.

We had a volunteer for our help project http://wikihost.org/wikis/pdfsharp/ ...
... but he vanished ...

Author:  Thomas [ Wed Aug 27, 2008 2:08 pm ]
Post subject: 

Thomas Hoevel wrote:
No change for page number (that's why you have to set the starting number).


Yes. It's a bit inconsistent I think. For all others:

//Resetting starting number
section.PageSetup.StartingNumber = 1;

// Current Page
AddPageField()

// Total Page Count
AddSectionPagesField()

Thomas Hoevel wrote:
Re: documentation:
I press F12 and look what's there.
Press F12 on AddNumPagesField and you'll find AddSectionPagesField.
I knew there was a way to set the starting page of a section; since I didn't find it in Section, I looked in PageSetup.

Apart from Intellisense there are no documents worth mentioning.
The samples are a good source of information.


IntelliSense would be a great help.

Thomas Hoevel wrote:
We had a volunteer for our help project http://pdfsharp.wikihost.org/ ...
... but he vanished ...


I know the situation of open source projects, I am involved in some. But I have not the time to get involved in this too, instead I would pay for a commercial version if offered for a fair price.

Just my 2 cents. Thanks again for your support.

Author:  Thomas Hoevel [ Wed Aug 27, 2008 2:34 pm ]
Post subject: 

IntelliSense works.
Did you include the MigraDoc projects in your solution?
Or did you reference the DLLs directly?

Author:  Thomas [ Wed Aug 27, 2008 3:11 pm ]
Post subject: 

It's a bit warm here :? Sorry, of course IntelliSense works. But it seems you did not set any XML Comments to provide more meaningful information within the IntelliSense popups.

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