I am new to Gembox pdf and want to use the software to create manuals for equipment we build which consist of many different pdf files from many different sources. I was just using one of the samples to test things out and I get the following error on one of the documents.
{“Unable to cast object of type ‘GemBox.Pdf.Objects.PdfIndirectObject’ to type ‘GemBox.Pdf.Objects.PdfArray’.”}
I have narrowed it down to annotations on a specific document, and if I clear them I don’t get the error anymore but in most cases I would like to keep them. Here is the sample code. I modified the code to do individual pages so I could figure out what page(s) was causing the issue. It turns out about 700 pages of this 2700 page document have this error.
Dim vPageList As New Collection
Dim vCount As Int16
Using document = New PdfDocument()
' Merge multiple PDF files into single PDF by loading source documents
' and cloning all their pages to destination document.
For Each fileName In PDFFiles
Using source As PdfDocument = PdfDocument.Load(fileName)
For Each vP As PdfPage In source.Pages
Try
vCount += 1
vP.Annotations.Clear()
document.Pages.Kids.AddClone(vP) 'source.Pages)
Catch ex As Exception
vPageList.Add(vCount)
End Try
Next
End Using
Next