We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

System.ArgumentException at Aspose.Pdf.PageCollection.Add(ICollection pages)

Hi,
I am running into an exception when trying to add pages to a document. Specifically I want to merge multiple documents into one, so I am using the document.Pages.Add method as recommended. I am testing with four files, and on the second one Aspose.Pdf throws an exception. The relevant code is as follows (error occurs on the bold line half way down) :

using (System.IO.FileStream output = new System.IO.FileStream(temporaryFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
using (System.IO.MemoryStream input = new System.IO.MemoryStream())
{
foreach (FilesToJSONObj o in objJSON)
{
int dlCount = 0;

                    var dlsession = v.ObjectFileOperations.DownloadFileInBlocks_BeginEx(o.FileVer.FileId.InternalId, o.FileVer.InternalVersion, MFFileFormat.MFFileFormatPDF);
                    dlCount = (int)dlsession.FileSize;
                    byte[] dlBuffer = v.ObjectFileOperations.DownloadFileInBlocks_ReadBlock(dlsession.DownloadID, dlCount, (long)0);
                    input.Write(dlBuffer, 0, dlBuffer.Length);

                    Document tmp = new Document(input);

                    //// optimize document
                    //tmp.Optimize();
                    **concPDF.Pages.Add(tmp.Pages)**;

                }
                //concPDF.Optimize();
                concPDF.Save(output, Aspose.Pdf.SaveFormat.Pdf);

                output.Flush();

                sourceObjectFiles.Add(-1, new SourceObjectFile()
                {
                    Extension = "pdf",
                    SourceFilePath = temporaryFilePath,
                    Title = concPDF.Info.Title
                });
            }
        }
Error message: System.ArgumentException HResult=0x80070057 Message=An attempt to create annotation using invalid dictionary. Source=Aspose.PDF StackTrace: at Aspose.Pdf.Annotations.Annotation.#=z3HYDyCg=(#=zeqPv5wX8l1s2hK00ogdKmgmkXLaj70A7Iw== #=zIlB3gH9gXBOE8FDTCw==, Page #=zKQHMiyU=) at Aspose.Pdf.Annotations.AnnotationCollection.#=zAUfHViyDX64E.#=zbk0Zhuxe1vlf() at Aspose.Pdf.Annotations.AnnotationCollection.#=zcvCd6O0=..ctor(List`1 #=z8QQ1xfU=, Page #=zKQHMiyU=) at Aspose.Pdf.Annotations.AnnotationCollection.GetEnumerator() at Aspose.Pdf.PageCollection.#=zpucJsIzXRgQX(Page #=zKQHMiyU=) at Aspose.Pdf.PageCollection.#=z0jQq_M0=(Page #=zeIA_7SY=, #=zjznvyO74l$_Ek9yG65NB6E6NMjAe #=zSnlT$2Mddeew) at Aspose.Pdf.PageCollection.#=z0jQq_M0=(ICollection`1 #=zxFHs8Oo=, #=zjznvyO74l$_Ek9yG65NB6E6NMjAe #=zSnlT$2Mddeew) at Aspose.Pdf.PageCollection.Add(ICollection`1 pages) at Coex.MFCustomizationsMFtoSTA.VaultmanagerCN.VaultApplication.GetConcatenatedPDF(Vault v, ObjVerEx obj, String startChar) in C:\Users\Bruker\source\repos\Coex.MFCustomizationsMFtoSTA.VaultmanagerCN\Coex.MFCustomizationsMFtoSTA.VaultmanagerCN\VaultApplication.cs:line 551 at Coex.MFCustomizationsMFtoSTA.VaultmanagerCN.VaultApplication.PostProcessingWorkflowStateHandler(StateEnvironment env) in C:\Users\Bruker\source\repos\Coex.MFCustomizationsMFtoSTA.VaultmanagerCN\Coex.MFCustomizationsMFtoSTA.VaultmanagerCN\VaultApplication.cs:line 101 at MFiles.VAF.StateMethodInfo.RunAction(StateEnvironment environment, IExecutionTrace trace)

I will attach the file in question as well. Funny thing is that file was an excel spreadsheet converted to PDF by another application, which also uses Aspose.

@brmykleb,

Thanks for contacting support.

Can you please share source file so that we may further investigate to help you out.

Any progress with this???
I guess it may also help knowing that the file I am trying to add was converted from .xlsx to .pdf by using Aspose as well. The version of the assembly Aspose.Pdf that this application uses is not the same as I am using for concateneting, could this be an issue??

Regards,
Torgeir

@brmykleb,

I like to inform I have worked with sample code share by you and that contain some undefined variables. Would you please share SSCCE code that you are using for this which I already requested you along with source files as well , so that we may try to reproduce and investigate it in our environment.