Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfDocumentProcessor.PasswordRequested Event

Occurs when requesting a security password to open a protected PDF file.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Docs.v24.2.dll

NuGet Package: DevExpress.Document.Processor

#Declaration

public event PdfPasswordRequestedEventHandler PasswordRequested

#Event Data

The PasswordRequested event's data class is PdfPasswordRequestedEventArgs. The following properties provide information specific to this event:

Property Description
FileName Returns the file name of a document that is requested to be opened in the PDF Viewer or PDF Document Processor.
FilePath Returns the path of the file requested to be opened in the PDF Viewer or PDF Document Processor.
Password Obsolete. This property is now obsolete. Use the PdfPasswordRequestedEventArgs.PasswordString property instead.
PasswordRequestsCount Returns the current number of password request attempts.
PasswordString Specifies the security password to open a PDF file.

#Remarks

To interrupt the password request process, the PdfPasswordRequestedEventArgs.PasswordString property value should be set to null.

An invalid password exception is raised when calling the PdfDocumentProcessor.LoadDocument method if the PdfPasswordRequestedEventArgs.PasswordString property has either the null value or when the password request limit is expired (all requests return an incorrect password).

To change the maximum number of allowed attempts to enter the PDF file’s security password, use the PdfDocumentProcessor.PasswordAttemptsLimit property (the default value is 1).

#Example

The following code illustrates the use of the PdfDocumentProcessor.PasswordRequested event.

using DevExpress.Pdf;

namespace RequestPassword {
    class Program {
        static void Main(string[] args) {
            using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) {

                // Handle the PasswordRequested event.             
                pdfDocumentProcessor.PasswordRequested += PdfDocumentProcessor_PasswordRequested;

                // Load a protected PDF document.
                pdfDocumentProcessor.LoadDocument(@"..\\..\\ProtectedDocument.pdf");

                // Unsubscribe from PasswordRequested event.
                pdfDocumentProcessor.PasswordRequested -= PdfDocumentProcessor_PasswordRequested;

                // Save the document.               
                pdfDocumentProcessor.SaveDocument("..\\..\\Result.pdf");
            }
        }

        private static void PdfDocumentProcessor_PasswordRequested(object sender, PdfPasswordRequestedEventArgs e) {
            e.PasswordString = "password";
        }
    }
}
See Also