Frequently Asked Question:
Testing for locked PDF’s
Question
Is there a method for testing existing PDF's (ie not created with Quick PDF) to see it they are locked? I have client supplied PDF's some of which are locked and do not merge in, when using mergedocument.
Answer
Here is some C# sample code to analyse a file to see if it is password protected:
private void AnalyseFile_Click(object sender, EventArgs e)
{
string[] item = { "Security Method", "User Password", "Master Password", "Printing",
"Changing the Document",
"Content Copying or Extraction", "Authoring Comments and Form Fields",
"Form Field Fill-in or Signing",
"Content Accessibility Enabled", "Document Assembly", "Encryption Level" };
string[] result = { "None", "Adobe Standard Security", "No", "Yes", "Fully Allowed",
"Not Allowed", "Allowed",
"40-bit RC4 (Acrobat 3.x, 4.x)", "128-bit RC4 (Acrobat 5.x)", "Unknown",
"Low resolution",
"Blank", "128-bit AES (Acrobat 7.x)" };
string filename = "4931 password.pdf";
string s;
int ret;
////////////////////////////
string msg = "Results from Ananysis()\n";
int aid = QP.AnalyseFile(filename, "");
for (int i=0;i<=10;i++)
{
string s1 = QP.GetAnalysisInfo(aid, i+20);
msg += String.Format("[{0}]{1} = [{2}]{3}\n", i, item[i], s1, result[int.Parse(s1)]);
}
QP.DeleteAnalysis(aid);
}