Fastest way to check PDF encryption

Question: Is there a faster way to determine if a PDF is “user” encrypted then using PdfFileInfo -> then checking .IsEncrypted and .HasOpenPassword?

I have noticed while debugging that PdfFileInfo can take up to 10 seconds to process a document and while not debugging between 150ms - 200ms even for files as small as 50kb.

var pdfFile = new PdfFileInfo(stream); // <--- Takes a long time
bool isEncrypted = pdfFile.HasOpenPassword;

I am working with a large number of PDF documents and OpenSearch to send the documents for faster search queries. To reduce the time it takes Open Search to process a document, I am checking if a PDF is encrypted prior to uploading the document so I don’t waste time during upload and processing.

I have written my own function to determine if a document is encrypted to try and speed things up and it takes 0 - 1ms to complete but I am afraid I am missing some of the nuances of PDFs and this may not always be successful. Is anything available to skip some of the steps PdfFileInfo takes to get this type of information?

Thanks

@OpenDevSolutions

Can you please share your environment details i.e. OS Name and Version, API Version, RAM size, etc.? Also, please share a sample PDF for our reference so that we can test the scenario in our environment and address it accordingly.

Environment: Windows 10
RAM: 32GB
CPU: AMD Ryzen 9 5950x 16-core (4.5Ghz)
Storage: Samsung 980 Pro NVMe
API Version: 23.3.0

Here is a sample password protected file Sample Password Protected File.pdf (4.8 MB)

@OpenDevSolutions

Due to some reason, we are unable to download the attachment. Can you please attach your file again so that we can further with the testing?

There is nothing special about the password protected file. It was just a sample found online. I will try to upload it again.

Sample Password Protected File.pdf (4.8 MB)

@OpenDevSolutions

We tested using 23.8 version of the API and the sample file that you shared. API took time in milliseconds. Can you please share in which scenario it takes up to 10 seconds? Can you please share that file with us? Also, please share some expected loading time so that we can investigate from that perspective.

The scenario in which I experienced 10 seconds to get the PdfFileInfo was during a debugging session in Visual studio (Attached debugger). It appears having a debugger attached took a heavy toll loading the aspose dll. When not debugging, the attached file took on average 120-150ms to complete the code above.

The file in which I experienced this was previously attached here.

My own version to determine whether the document is encrypted takes 0-4ms to complete so I would expect a similar time to that.

My original question is in regards to using a different approach to determining if a document is encrypted. I imagine PdfFileInfo is performing a bunch of other steps that are not necessary for my use case. My goal is simply to know if I could open a PDF without a password or not. If this is the only option Aspose provides, I will just use my own implementation.

@OpenDevSolutions

We have Document.IsEncrypted property which is true when document is encrypted (and password-protected) but we suspect this will take a long time too.

It looks like something in the document causes re-reading the entire document to build cross-reference table. Therefore, for further investigation, PDFNET-55349 ticket has been logged in our issue tracking system. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.