I am currently having an issue using the Aspose.Pdf.Kit.PdfFileEditor.Concatenate function.
I am using it to concatenate streams into a final document. The function returns True, so I believe it is working, however, the output stream is returned in a closed state.
I tried using the following overloads with the same result:
- Concatenate(System.IO.Stream(), System.IO.Stream)
- Concatenate(System.IO.Stream, System.IO.Stream, System.IO.Stream)
Here is some sample code that reproduces the issue (this code is referencing version 220.127.116.11 of the Aspose.Pdf.Kit.dll file)
Dim inFile1 As String = "c:\example1.pdf" Dim inFile2 As String = "c:\example2.pdf" Dim outFile As String = "c:\out.pdf" Dim inStream1 As FileStream = New FileStream(inFile1, FileMode.Open) Dim inStream2 As fileStream = New FileStream(inFile2, FileMode.Open) Dim outputStream As FileStream = New FileStream(outFile, FileMode.Create) Dim innerStream As MemoryStream = New MemoryStream()
'Concatnate input Pdf file1 and file2, output is saved in innerStream. Dim editor As PdfFileEditor = New PdfFileEditor() Dim bReturn As Boolean bReturn = editor.Concatenate(inStream1, inStream2, innerStream) Debug.WriteLine("bReturn = " & bReturn) Debug.WriteLine("Is Stream Closed? " & Not innerStream.CanRead()) Try 'At This point, innerStream is closed, and will throw an exception if accessed. Debug.Print("Stream Size: " & innerStream.Length) Catch ex As Exception Debug.WriteLine(ex.Message) End Try outputStream.Close() innerStream.Close()</PRE><PRE> </PRE>The Output is: <PRE>bReturn = True
Is Stream Closed? True
A first chance exception of type ‘System.ObjectDisposedException’ occurred in mscorlib.dll
Cannot access a closed Stream.
Thanks for your assistance.