PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Aug 17, 2018 10:46 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Apr 23, 2018 8:02 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 23
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!


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 23, 2018 8:11 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 23, 2018 8:33 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 23
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 23, 2018 8:55 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 26, 2018 8:43 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 23
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";


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 27, 2018 5:56 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue May 01, 2018 2:55 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 23
Hack or not, now that it works I won't be given time to implement the linked solution in our environment. :roll:


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

All times are UTC


Who is online

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