2 years ago
#52823
M. Rogers
How to load a PDF stored as a Stream
I have a PDF document stored as a Stream object, and I am trying to load the data into a PDDocument. This seems like a straight forward task, but I can't seem to figure out how to do it without saving the stream locally first. Below is my code.
using (MemoryStream stream = new MemoryStream())
{
await _Results[0].FileData.CopyToAsync(stream);
InputStream tempStream = new ByteArrayInputStream(stream.ToArray());
PDDocument doc = PDDocument.load(tempStream);
tempStream.close();
}
Here "_Results[0].FileData" is the pdf stored as a Stream and I know the data is correctly saved. The program crashed on the load line with the following.
Any insight on how to do this or where I'm going wrong would be appreciated.
c#
pdfbox
0 Answers
Your Answer