Hello!
I’ve faced an issue while using Aspose.Words product described below.
And will be extremely grateful for any assistance.
Issue description
The problem revealed when I have tried to load the PDF document using a MemoryStream created from byte array. When I am calling new Document(memoryStream);
it throws the exception below.
It works fine with docx
documents or with same PDF
and FileStream
. But I am using Aspose.Words in the web app and I do want to avoid any interaction with a file system.
Exception
Aspose.Words.FileCorruptedException
HResult=0x80131500
Message=The document appears to be corrupted and cannot be loaded.
Source=Aspose.Words
StackTrace:
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document..ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document..ctor(Stream stream)
at CompareDocs.AsposeTest.Program.Main(String[] args) in C:\Users\Serhii_Iordanov\source\repos\CompareDocs\CompareDocs.Aspose\Program.cs:line 24
This exception was originally thrown at this call stack:
System.IO.MemoryStream.Position.get()
Aspose.Words.Document.(System.IO.Stream, Aspose.Words.LoadOptions)
Inner Exception 1:
ObjectDisposedException: Cannot access a closed Stream.
Code examples
byte[] documentBytes;
using (var fileStream = new FileStream("new.pdf", FileMode.Open))
{
documentBytes = new byte[fileStream.Length];
fileStream.Read(documentBytes, 0, (int)fileStream.Length);
}
using (var memoryStream = new MemoryStream(documentBytes))
{
var document = new Document(memoryStream); // <- an exception goes here
}
Additional information
Aspose.Words version: 20.3.0
Execution environment: .NET Core 3.1, Windows
Tested on different valid PDF files