PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 5:11 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Nov 21, 2016 11:54 pm 
Offline

Joined: Tue Dec 08, 2009 10:05 am
Posts: 19
I've currently got a document I build with migradoc... I then come in and import pages from another pdf at the end. I've basically added a dummy section to the end of the document where I currently put a bookmark and all works well.. (but puts a blank page before the addendum documents.

Is there a way to either append the table of contents section with pdfsharp, or maybe open the document up with pdfsharp, add a bookmark that matches the same name I added in addpagereflink?

I've got this working, but know I could make this cleaner. I'd appreciate any advice.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 22, 2016 5:02 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Hi!
ronnyek wrote:
Is there a way to either append the table of contents section with pdfsharp, or maybe open the document up with pdfsharp, add a bookmark that matches the same name I added in addpagereflink?
There are several ways. But the MigraDoc bookmark names are not included in the PDF.

You can draw the first imported PDF page on the blank page created by the dummy section. That would be a clean and simple way to avoid the blank page.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 23, 2016 3:58 am 
Offline

Joined: Tue Dec 08, 2009 10:05 am
Posts: 19
Ok I think I understand you... so I created a new section at the end of the doc with a paragraph that literally had nothing but a bookmark.

Then for the pages I intend to append the original pdf with, I've tried to basically get an Ximage from the first pdfpage, and drawimage with it. My problem is that I cant seem to find a successful way to actually get an XImage from that pdf page.

I tried to write the first page to a new document to a memorystream, then do XPdfForm.FromStream(), but it keeps failing with no valid pdf header found on document. If I write to a temp file I get the same error, however opening the file in a pdfviewer I get the first page of the addendum no problem.

I'm undoubtedly overdoing this... is there an easier way to just give me an ximage that I can then write to the last page of the first doc (and then subsequent pages I can just add to the original doc?

I appreciate the time.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 23, 2016 2:21 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

Check the Two Pages on One sample:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

Get an XPdfForm for the PDF file you want to import and draw it like an image.

Code:
XPdfForm form = XPdfForm.FromFile(filename);
// ...
gfx.DrawImage(form, box);

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 23, 2016 6:58 pm 
Offline

Joined: Tue Dec 08, 2009 10:05 am
Posts: 19
I've attempted that very thing.

Should XPdfForm.FromFile / FromStream create an image of the entire other pdf, (eg, do I need to first write the first page to another temp stream or file?)

When I do this, no matter what I do, I get an error saying the file / stream doesnt contain a valid PDF header. I've opened it up in adobe/chrome with no problems, and can look at all the original header information... and simply opening as a pdfdocument and adding pages from one doc to the other works like a charm (just broken table of contents).


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 24, 2016 9:22 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
ronnyek wrote:
do I need to first write the first page to another temp stream or file?
No. The sample I mentioned does not do anything like that.

Could be a bug in your code, could be an issue with your PDF file.
If you send us a Visual Studio solution that allows us to replicate the issue then we will investigate it.
See also:
viewtopic.php?f=2&t=832

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 143 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