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

How can I add pages to a Migradoc document object from file?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3772
Page 1 of 1

Author:  vorobej [ Mon Apr 23, 2018 8:02 pm ]
Post subject:  How can I add pages to a Migradoc document object from file?

There is a Wiki page showing how to add pages to a PdfSharp document.
I also found samples of adding pages from a Migradoc document to a PdfSharp document.

But what I am looking for is the reverse: to add pages from an on-disk PDF file to an in-memory Migradoc document.
Can anyone please provide any pointers to the API that can be used for that?

Thank you!

Author:  TH-Soft [ Mon Apr 23, 2018 8:11 pm ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

You can use the MigraDoc Image class to add pages from a PDF file to a MigraDoc document.
You can size the image to fill the complete page when needed.

Use the hash sign and a page number after the filename to select a specific page (e.g. "test.pdf#5" for the fifth page).

Note that these image only work when rendering to PDF.

Author:  vorobej [ Mon Apr 23, 2018 8:33 pm ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

TH-Soft wrote:
Use the hash sign and a page number after the filename to select a specific page (e.g. "test.pdf#5" for the fifth page).

So I can use PdfSharp to find out the number of pages in the appendix PDF, then iterate with Migradoc image?
Sounds brilliant, thanks a lot!

PS: Where is this documented, just out of curiosity?

Author:  TH-Soft [ Mon Apr 23, 2018 8:55 pm ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

vorobej wrote:
PS: Where is this documented, just out of curiosity?
I dunno.
That info is surely still missing in the Wiki. I'll try to remember to add it some day.

Common knowledge, now documented in this thread. :wink:

Well, actually it's a feature of PDFsharp's XImage class - but documentation of this feature is also rather discreet.

Author:  vorobej [ Thu Apr 26, 2018 8:43 pm ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

Finally developed enough to test that section of the code, and it worked - woo hoo!
The pages from the PDF template were being inserted within the margins of the existing document, off to the right and bottom.
I tried setting Left to -2.5cm and Top to -5cm and that shifted the pages left and up, but still not high enough vertically.
Basically, it does not matter what value I put into Top: -2cm or -5cm, it is still the same vertical distance down from the top and is not moving any higher.
Is there any way to move the inserted image further up?

For this to work, will I have to save my original document into a custom paper size format with no margins and page size reduced by the margin widths? That would be very unfortunate, as the template is owned by non-technical folks.

Ah! Figured it's as simple as that:

Code:
                section.PageSetup.TopMargin = "0cm";
                section.PageSetup.LeftMargin = "0cm";

Author:  TH-Soft [ Fri Apr 27, 2018 5:56 am ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

vorobej wrote:
Ah! Figured it's as simple as that
That looks like a dirty ugly hack.

Here's a post that places images at 2cm/2cm, but should also work for 0cm/0cm without messing up the page setup:
viewtopic.php?p=9038#p9038

For a full-page image you also have to set the image size to fill the complete page.

Author:  vorobej [ Tue May 01, 2018 2:55 pm ]
Post subject:  Re: How can I add pages to a Migradoc document object from f

Hack or not, now that it works I won't be given time to implement the linked solution in our environment. :roll:

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