Free Support Forum - aspose.com

Detecting if Aspose.PDF can handle a stream

Hi there,

We are currently trying to outline a strategy for detecting the Aspose component (starting from Detect file types from stream) that could handle a stream based on utilities function like:

                var fileFormatInfo = Aspose.Cells.FileFormatUtil.DetectFileFormat(input);
                if (fileFormatInfo.LoadFormat != Aspose.Cells.LoadFormat.Unknown)
                {
                    canHandle = true;
                }

Aspose.PDF 20.3.0 does not have such utilities functions and the one that the aforementioned post suggests is:

                    try
                    {
                        input.Position = 0L;
                
                        using (var doc = new Aspose.Pdf.Document(input))
                        {                                
                        }
                
                        canHandle = true;
                    }
                    catch (Exception)
                    {
                    }

The problem is that this approach for Aspose.PDF is time/resource consuming and we were wondering if there are other ways to check this with the latest of Aspose.PDF:

  1. utilities like Aspose.Words.FileFormatUtil.DetectFileFormat(input) or even the Aspose.CAD.Image.CanLoad(input)
  2. at least the possibility to shallow-load a stream into a Document just for the purpose of checking if it is a stream that the component could handle

Thank you!

@gwert

Thanks for contacting support.

We have logged an enhancement request as PDFNET-47875 in our issue tracking system for your requirements. We will further investigate the feasibility of required feature and keep you informed with the status of its availability. Please be patient and spare us little time.

We are sorry for the inconvenience.