InvalidCastException when merging

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  InvalidCastException when merging

DynamicPDF CoreSuite for .NET (v9) Forum

 Feb 15 2018 7:04 PM
I have a pdf containing 2 pages of 4 color bars used for cleaning print heads for one of our printers. I was asked to create a pdf with 10 such pages so I tried using the Merger to merge this pdf into itself. I also tried creating a copy of the pdf and then merging the copy into the original just once. I get a System.InvalidCastException: Unable to cast object of type 'zz93.ab0' to type 'zz93.ab1'. Below is the code I am using:

MergeDocument mergeDoc = MergeDocument.Merge(@"C:\temp\PDF\StartPageForIQ_rotated.pdf", @"C:\temp\PDF\StartPageForIQ_rotated - Copy.pdf");
mergeDoc.Draw(@"C:\temp\PDF\StartPageForIQ_new.pdf");

The first line with the MergeDocument delcaration and assignment is giving me the Exception. I tried just creating a MergeDocument from one of those pdfs and calling MergeDocument.Append() on it and got the same exception. Example is below:

MergeDocument mergeDoc = new MergeDocument(@"C:\temp\PDF\StartPageForIQ_rotated.pdf");
mergeDoc.Append(@"C:\temp\PDF\StartPageForIQ_rotated - Copy.pdf"); <-- Exception happens here
mergeDoc.Draw(@"C:\temp\PDF\StartPageForIQ_new.pdf");

I am using ceTe.DynamicPDF.40.dll version 9.0.0.40 Build 35525. I am using a 64-bit computer and have tried targeting both 64 and 32-bits in my project. I am running Visual Studio 2013 on Windows 7.
 Feb 16 2018 10:10 AM
Posted by a ceTe Software moderator
Hello,

Please email the PDFs you are trying to merge along with the link to this forum post to support@cete.com so we can recreate the error and look into this issue further.

Thanks,
ceTe Software Support Team.
Posted by a ceTe Software moderator
Hello,

We are able to recreate the error and we will look into it further. In the meantime you can use the following workaround to merge the PDF several times.

            PdfDocument pdf = new PdfDocument("StartPageForIQ_rotated.pdf");
            MergeOptions options = MergeOptions.All;
            options.EmbeddedFiles = false;
            MergeDocument document = new MergeDocument();
            document.Append(pdf);
            for (int i = 0; i < 4;i++ )
                document.Append(pdf, options);

            document.Draw("output.pdf");

It looks like the error is caused due to the file attachments embedded in the PDF and the above code will avoid importing those attachments for subsequent merges.

Thanks,
ceTe Software Support Team.
Thanks for taking a look into this. I didn't even see the attachment until you pointed it out. I'll remember that for next time.

All times are US Eastern Standard time. The time now is 1:43 PM.