Inspect properties of a PDF document

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Going Deeper > Document Engines > Working with PDF > Processing >

Inspect properties of a PDF document

In this section we present example code to inspect the properties of a PDF document. Before proceeding further please make sure that the prerequisite steps as listed in the Document Engines parent topic are followed.

 

Given below is the sample code.

 

using (var pdfDoc = new PDF())
{
   pdfDoc.LoadDocument("statement.pdf, password: "");
   PDFDocInfo pdfDocInfo = pdfDoc.DocInfo as PDFDocInfo;
   Console.WriteLine("Title: " + pdfDocInfo.Title);
   Console.WriteLine("Author: " + pdfDocInfo.Author);
   Console.WriteLine("Subject: " + pdfDocInfo.Subject);
   Console.WriteLine("Keywords: " + pdfDocInfo.Keywords);
   Console.WriteLine("Creator: " + pdfDocInfo.Creator);
   Console.WriteLine("Producer: " + pdfDocInfo.Producer);
   Console.WriteLine("CreationDate: " + pdfDocInfo.CreationDate);
   Console.WriteLine("ModifiedDate: " + pdfDocInfo.ModifiedDate);
   Console.WriteLine("IsEncrypted: " + pdfDocInfo.IsEncrypted);
   if (pdfDocInfo.IsEncrypted)
   {
      Console.WriteLine("  EncryptionMethod: " + pdfDocInfo.EncryptionInfo.EncryptionMethod);
      if (pdfDocInfo.EncryptionInfo.EncryptionMethod == PDFEncryptionMethod.PasswordEncryption)
      {
         var passwordEncryptionInfo = pdfDocInfo.EncryptionInfo.PasswordEncryptionInfo;
         Console.WriteLine("  EncryptionLevel: " + passwordEncryptionInfo.EncryptionLevel);
         Console.WriteLine("  HasOpenPassword: " + passwordEncryptionInfo.HasOpenPassword);
         Console.WriteLine("  HasPermissionsPassword: " + passwordEncryptionInfo.HasPermissionsPassword);
         Console.WriteLine("  Currently opened as user: " + passwordEncryptionInfo.IsUser);
         Console.WriteLine("  Currently opened as owner: " + passwordEncryptionInfo.IsOwner);
         if (passwordEncryptionInfo.HasPermissionsPassword)
         {
            Console.WriteLine("    Permissions");
            Console.WriteLine("      IsAssembleDocAllowed: " + passwordEncryptionInfo.IsAssembleDocAllowed);
            Console.WriteLine("      IsCommentingAllowed: " + passwordEncryptionInfo.IsCommentingAllowed);
            Console.WriteLine("      IsContentAccessibilityAllowed: " + passwordEncryptionInfo.IsContentAccessibilityAllowed);
            Console.WriteLine("      IsContentCopyExtractAllowed: " + passwordEncryptionInfo.IsContentCopyExtractAllowed);
            Console.WriteLine("      IsFormFillSignAllowed: " + passwordEncryptionInfo.IsFormFillSignAllowed);
            Console.WriteLine("      IsHighResPrintAllowed: " + passwordEncryptionInfo.IsHighResPrintAllowed);
            Console.WriteLine("      IsLowResPrintAllowed: " + passwordEncryptionInfo.IsLowResPrintAllowed);
            Console.WriteLine("      IsModifyDocAllowed: " + passwordEncryptionInfo.IsModifyDocAllowed);
         }
      }
   }
}