PDFsharp & MigraDoc Foundation

PDFSharp Outline Help
Page 1 of 1

Author:  J_Adams [ Tue Jan 14, 2020 8:55 pm ]
Post subject:  PDFSharp Outline Help

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:

//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];

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

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

This exception was originally thrown at this call stack:

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group