In fact, TPdfEncryption.New() will create the expected TPdfEncryption instance, depending on the supplied encryption Level:

    class function TPdfEncryption.New(aLevel: TPdfEncryptionLevel;
      const aUserPassword, aOwnerPassword: string;
      aPermissions: TPdfEncryptionPermissions): TPdfEncryption;

Here are some comments about this new method:

  • to be called as parameter of TPdfDocument/TPdfDocumentGDI.Create()
  • currently, only elRC4_40 and elRC4_128 levels are implemented
  • both passwords are expected to be ASCII-7 characters only
  • aUserPassword will be asked at file opening: to be set to '' for not blocking display, but optional permission
  • aOwnerPassword shall not be '', and will be used internally to cypher the pdf file content
  • aPermissions can be either one of the PDF_PERMISSION_ALL / PDF_PERMISSION_NOMODIF / PDF_PERSMISSION_NOPRINT / PDF_PERMISSION_NOCOPY / PDF_PERMISSION_NOCOPYNORPRINT set of options

In practice, typical use may be:

 Doc := TPdfDocument.Create(false,0,false,
   TPdfEncryption.New(elRC4_40,'','toto',PDF_PERMISSION_NOMODIF));
 Doc := TPdfDocument.Create(false,0,false,
   TPdfEncryption.New(elRC4_128,'','toto',PDF_PERMISSION_NOCOPYNORPRINT));

Follow this link to get the latest trunk (unstable) version.

Feedback is welcome on our forum, as usual!