In This Topic
    Load an encrypted PDF
    In This Topic

    Introduction

    The following example demonstrates how to load a PDF document that was encrypted with a password. 

    Load an encrypted PDF document
    Copy Code
    public static void LoadWithPassword()
    {
      Console.WriteLine( "=== LOAD WITH PASSWORD ===" );
      var fileName = "encrypted.pdf";
    
      // Defines the LoadingOptions.
      var loadingOptions = new LoadOptions() { Password = "kanbanery" };
    
      // Loads an encrypted PdfDocument with a password.
      using( var pdfDoc = PdfDocument.Load( EncryptionsSample.EncryptionsSampleResourcesDirectory + $"{fileName}", loadingOptions ) )
      {
        // Gets the first Page.
        var page = pdfDoc.Pages.First();
    
        // Gets the text of the first page.
        var text = page.Text;
    
        Debug.Assert( "Encrypted pdf" == text );
      }
    }

    See Also