I am using Aspose.pdf version 20.4.0
This dll used for checking whether the PDF is password protected.
While converting the Stream to PdfFileInfo, i am getting below exception
PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization. (Reason: Startxref not found)
I have used below code for checking the protected file and this is running in an API .net core 2.1 version .
public static bool IsFilePasswordProtected(Stream stream, string extension, out string remarks)
{
remarks = string.Empty;
switch (extension)
{
case pdf:
PdfFileInfo pdfFileInfo = new PdfFileInfo(stream);
bool hasPassword = pdfFileInfo.HasOpenPassword;
pdfFileInfo.Dispose();
pdfFileInfo.Close();
remarks = hasPassword ? password_protected : "";
return hasPassword;
default:
return false;
}
}
Please let me know if more details required.