PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 25, 2020 9:21 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: PDFSharp Outline Help
PostPosted: Tue Jan 14, 2020 8:55 pm 
Offline

Joined: Tue Jan 14, 2020 8:22 pm
Posts: 1
Hello! Thank you for such a wonderful tool!

I am making a small program that appends a page to a large PDF file and creates a new bookmark for it using a name provided by the user. It will work with my test files - no outline and single level outline - but will throw an exception when I try using a multi-level outline as my destination:

Code:
//Open the files
PdfDocument inputDestination = PdfReader.Open(pathDestination, PdfDocumentOpenMode.Import);
PdfDocument inputSource = PdfReader.Open(pathSource, PdfDocumentOpenMode.Import);

//Inserts the Source page in to the ScanDoc
PdfPage newPage = inputSource.Pages[0];
inputDestination.AddPage(newPage);

//Bookmarking
string bookmarkName = Interaction.InputBox("Please provide a name for the bookmark:", "New Bookmark");
int count = inputDestination.PageCount -1;
PdfPage lastPage = inputDestination.Pages[count];
PdfOutline outline = inputDestination.Outlines.Add(bookmarkName, lastPage);

//Saves the ScanDoc
inputDestination.Save(pathDestination);


Throws an error against that last line of my "Bookmarking" block:
Code:
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

This exception was originally thrown at this call stack:
   PdfSharp.Pdf.PdfOutline.SplitDestinationPage(PdfSharp.Pdf.PdfArray)
   PdfSharp.Pdf.PdfOutline.Initialize()
   PdfSharp.Pdf.PdfOutline.InitializeChildren()
   PdfSharp.Pdf.PdfOutline.Initialize()
   PdfSharp.Pdf.PdfOutline.InitializeChildren()
   PdfSharp.Pdf.PdfOutline.Initialize()
   PdfSharp.Pdf.PdfOutline.InitializeChildren()
   PdfSharp.Pdf.PdfOutline.Initialize()
   PdfSharp.Pdf.PdfOutline.PdfOutline(PdfSharp.Pdf.PdfDictionary)


I know I am missing something with the levels, but I cannot find anything in the documentation. I just need the bookmark created in the tree, it can be manually moved where needed.

My thanks in advance for any advice or direction anyone can provide.


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

All times are UTC


Who is online

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