Question

I have seen open source and commercial PDF components which support Dot net implementation, I think almost every available component in market,but the strange to identify a document that is protected or not, every one is showing in the form of exception rather than a property.Is there anything tricky behind this? I would expect

Component.Load(inputFile.pdf);
If(Component.isProtected)
{
Component.Open(inputFile.pdf,password);
}
else
{
Component.Open(inputFile.pdf);
}

instead of the following regular approach

Try{
Component.Open(inputFile.pdf);
}
catch(Exception ex)
{
//bad password
//Some exception
}
Was it helpful?

Solution 2

This is possible with Aspose.Pdf for .NET, which is a commercial .NET component. It has a boolean property IsEncrypted for encrypted file detection. Sample code is given below.

// load the source PDF doucment
PdfFileInfo fileInfo = new PdfFileInfo(dataDir + "protected.pdf");
// determine that source PDF file is Encrypted with password
bool encrypted = fileInfo.IsEncrypted;
MessageBox.Show("Encrypted: " + encrypted);

I work for Aspose as a Developer Evangelist.

OTHER TIPS

All can be detected basically by checking for the respective "dictionaries" as described on pages 115 - 136 of the PDF spec: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top