I am trying to combine pdf's into a single document and add bookmarks for the individual pages as they are added. My code works for combining the pdf's, however when I attempt to add a bookmark I get an exception. I am using the most basic PdfOutline constructor with a defaulted name just to try and get the thing running -- I keep getting an unknown exception when I create the book mark though. Does anyone have any idea why?
Code:
foreach (DirectoryInfo D in MySubs)
{
currentFileTitle.Text = D.Name.ToString();
processCounter.Text = counter.ToString() + " of " + MySubs.Length.ToString() + " files processed";
// Get PDF's from directory
string[] pdfs = GetFiles(D.FullName.ToString());
if (pdfs.Length <= 0) break;
// Create the output document
PdfDocument outputDocument = new PdfDocument();
// Iterate files
foreach (string file in pdfs)
{
// Open the document to import pages from it.
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
// Iterate pages
for (int idx = 0; idx < inputDocument.PageCount; idx++)
{
// Get the page from the external document...
PdfPage page = inputDocument.Pages[idx];
//Create outline (bookmark)
PdfOutline bookmark = outputDocument.Outlines.Add("test", page);
// ...and add it to the output document.
outputDocument.AddPage(page);
}
}
// Save the document...
outputDocument.Save(toFilePath + "//" + D.Name + ".pdf");
}