PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

key must be of type System.String when accessing pagecount
https://forum.pdfsharp.net/viewtopic.php?f=2&t=439
Page 1 of 1

Author:  echristo21 [ Fri Jul 25, 2008 6:23 pm ]
Post subject:  key must be of type System.String when accessing pagecount

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);
                }
            }


        }

Author:  echristo21 [ Fri Jul 25, 2008 6:48 pm ]
Post subject: 

Just to add on to the above message. I noticed this when I was debugging, I am not sure if this is related at all.

Object reference not set to an instance of an object.

at PdfSharp.Pdf.PdfDictionary.DictionaryElements.CreateDictionary(Type type, PdfDictionary oldDictionary)
at PdfSharp.Pdf.PdfDictionary.DictionaryElements.GetValue(String key, VCF options)
at PdfSharp.Pdf.Advanced.PdfCatalog.get_Outlines()
at PdfSharp.Pdf.PdfDocument.get_Outlines()


Any help?

Author:  Thomas Hoevel [ Mon Jul 28, 2008 8:13 am ]
Post subject: 

Which version of PDFsharp do you use?
If this problem also occurs with the current PDFsharp 1.2 then please provide us the PDF file that causes this error.

Author:  echristo21 [ Thu Aug 14, 2008 5:32 pm ]
Post subject: 

I upgraded to the newest version and it fixed this problem. Thanks!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/