GemBox Support Forum

Cast error using Pages.Kids.AddClone

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
                        vCount += 1

                        document.Pages.Kids.AddClone(vP) 'source.Pages)

                    Catch ex As Exception
                    End Try
            End Using

Hi Dave,
Can you please send us your PDF so that we can reproduce this issue and investigate it?

Sent a link by e-mail. Thanks.

This issue was resolved in this latest bugfix:

Or in this latest NuGet package:
Install-Package GemBox.Pdf -Version 17.0.1168-hotfix