encryptionOptions property

PdfEncryptionOptions get encryptionOptions

Gets or sets the type of encryption options used.

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';
security.encryptionOptions = PdfEncryptionOptions.encryptAllContents;
//Create and add attachment to the PDF document
document.attachments.add(PdfAttachment(
  'input.txt', File('input.txt').readAsBytesSync(),
  description: 'Text File', mimeType: 'application/txt'));
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfEncryptionOptions get encryptionOptions =>
    _helper.encryptor.encryptionOptions;
set encryptionOptions (PdfEncryptionOptions value)

Implementation

set encryptionOptions(PdfEncryptionOptions value) {
  if (_helper.conformance) {
    throw ArgumentError(
        'Document encryption is not allowed with Conformance documents.');
  }
  if (_helper.encryptor.encryptionOptions != value) {
    _helper.encryptor.encryptionOptions = value;
    _helper.encryptor.encrypt = true;
    _helper.encryptor.changed = true;
    _helper.modifiedSecurity = true;
    _helper.encryptor.hasComputedPasswordValues = false;
    if (PdfEncryptionOptions.encryptOnlyAttachments == value) {
      _helper.encryptAttachments = true;
      _helper.encryptor.encryptMetadata = false;
    } else if (PdfEncryptionOptions.encryptAllContentsExceptMetadata ==
        value) {
      _helper.encryptAttachments = false;
      _helper.encryptor.encryptMetadata = false;
    } else {
      _helper.encryptAttachments = false;
      _helper.encryptor.encryptMetadata = true;
    }
  }
}