Detect encrypted Pdf document using C#, DotNet, Aspose.pdf
#region "Description"
/*
Method
given in blog can be used to determine if a pdf document is password protected
or not
1) Add reference to Aspose.Pdf dll in
your project
2) Add
reference to Aspose.Pdf namespace in your class
e.g.(
using Aspose.Pdf; )
2) Copy isPasswordProtectedPDFDoc()
method in your class
*/
#endregion
#region "Method"
public bool
isPasswordProtectedPDFDoc(Stream fileDataStream)
{
bool
isPasswordProtected = false;
try
{
Aspose.Pdf.Facades.PdfFileInfo fileInfo
= new Aspose.Pdf.Facades.PdfFileInfo(fileDataStream);
if
(fileInfo.IsEncrypted)
isPasswordProtected = true;
Aspose.Pdf.Document doccurrept = new Aspose.Pdf.Document(fileDataStream);
}
catch
(Aspose.Pdf.Exceptions.InvalidPasswordException)
{
isPasswordProtected = true;
}
catch
(Exception exc)
{
//objfileprops.iscorrupted
= true;
}
return
isPasswordProtected;
}
#endregion
No comments:
Post a Comment