Issue with processing PDF from Azure Blob Storage (Stream)

I have encountered a strange issue. We have PDF documents stored in Azure blob storage which we read into a stream object. The below code works for most documents:

var pdfDocument = new Aspose.Pdf.Document(docStream);
var pageNo = 0;
foreach (var pdfPage in pdfDocument.Pages)
{

}

However, for certain PDFs the foreach threw an exception with very little explanation. As a workaround, we save the PDF stream to a file and then recreated the PDF object like below and it started working without any issue.

var pdfDocument = new Aspose.Pdf.Document(docStream);
pdfDocument.Save(Path.Combine(ObjectDirecotry, referenceDoc.document_name));
pdfDocument = new Aspose.Pdf.Document(Path.Combine(ObjectDirecotry, referenceDoc.document_name));
var pageNo = 0;
foreach (var pdfPage in pdfDocument.Pages)
{

}

Any insight or guidance will be helpful.

Many thanks.

@vghodekar

We are afraid that we cannot comment much on this situation without replicating and observing the issue in our environment. If possible, can you please share the problematic PDF file with which we can try to reproduce the issue by reading it with Stream?

1 Like

Thanks for the response. Will get permission to share the document and try to share it in the next few days. Is there a way to share the document without posting it publicly?

@vghodekar

Yes, you can share it via private message. Please click on username and press Blue Message Button to send a private message.