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.