I created the following code to merge two pdfs into a single document. It works most of the time. However, one pdf throws an error when trying to retrieve the pagecount(bolded below). The error message says:key must be of type System.String.
Code:
/// <summary>
/// Merges two pdf into single document
/// </summary>
/// <param name="file"></param>
/// <param name="title"></param>
private void Merge(MemoryStream file, string title)
{
// Open the document to import pages from it.
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
// Iterate pages- Next line causes problems
[b]int count = inputDocument.PageCount;[/b]
for (int idx = 0; idx < count; idx++)
{
PdfPage page = inputDocument.Pages[idx];
sourceDcoument.AddPage(page);
if (idx == 0 && title.Length > 0)
{
pageBookmarks.Add(title);
}
else
{
pageBookmarks.Add(string.Empty);
}
}
}