userPassword property

String get userPassword

Gets the user password.

User password is required when the PDF document is opened in a viewer.

//Load an exisiting PDF document.
PdfDocument document = PdfDocument.fromBase64String(pdfData, 'password');
//Get the user password.
String userPassword = document.security.userPassword;
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

String get userPassword {
  return _helper.encryptor.userPassword;
}
set userPassword (String value)

Sets the user password.

User password is required when the PDF document is opened in a viewer.

//Create a new PDF document.
PdfDocument document = PdfDocument();
//Document security
PdfSecurity security = document.security;
//Set security options
security.algorithm = PdfEncryptionAlgorithm.rc4x128Bit;
security.userPassword = 'password';
security.ownerPassword = 'syncfusion';
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

set userPassword(String value) {
  if (_helper.conformance) {
    throw ArgumentError(
        'Document encryption is not allowed with Conformance documents.');
  }
  _helper.encryptor.userPassword = value;
  _helper.encryptor.encrypt = true;
  _helper.modifiedSecurity = true;
}