Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

void wxPdfDocument::SetProtection ( int  permissions,
const wxString &  userPassword = wxEmptyString,
const wxString &  ownerPassword = wxEmptyString,
wxPdfEncryptionMethod  encryptionMethod = wxPDF_ENCRYPTION_RC4V1,
int  keyLength = 0 
) [virtual]

Set permissions as well as user and owner passwords.

Parameters:
permissionsflag indicating permissions. Flags from the following list may be combined as needed If a value is present it means that the permission is granted
userPassworduser password if applicable. If a user password is set, user will be prompted before document is opened
ownerPasswordowner password.if applicable If an owner password is set, the document can be opened in privilege mode with no restriction if that password is entered
encryptionMethodselects the encryption method. Possible values are:

  • wxPDF_ENCRYPTION_RC4V1 RC4 method, version 1, with 40 bit encryption key (default)
  • wxPDF_ENCRYPTION_RC4V2 RC4 method, version 2, with 40..128 bit encryption key
  • wxPDF_ENCRYPTION_AESV2 AES method, with 128 bit encryption key
keyLengthLength of the key used for encryption (Default: 0) The default value selects the standard encryption method revision 2 with a key length of 40 bits. Specifying a value > 0 selects the standard encryption method revision 3 with the given key length, the key length has to be in the range 40..128 and has to be dividable by 8. The key length is adjusted accordingly if these conditions are not met. NOTE: Adobe Reader supports only 40- and 128-bit encryption keys.

Definition at line 365 of file pdfdoc.cpp.

References wxPdfEncrypt::GenerateEncryptionKey(), GetUniqueId(), m_encrypted, m_encryptor, m_PDFVersion, wxPDF_PERMISSION_ANNOT, wxPDF_PERMISSION_COPY, wxPDF_PERMISSION_MODIFY, and wxPDF_PERMISSION_PRINT.

{
  if (m_encryptor == NULL)
  {
    int revision = (keyLength > 0) ? 3 : 2;
    switch (encryptionMethod)
    {
      case wxPDF_ENCRYPTION_AESV2:
        revision = 4;
        if (m_PDFVersion < _T("1.6"))
        {
          m_PDFVersion = _T("1.6");
        }
        break;
      case wxPDF_ENCRYPTION_RC4V2:
        revision = 3;
        break;
      case wxPDF_ENCRYPTION_RC4V1:
      default:
        revision = 2;
        break;
    }
    m_encryptor = new wxPdfEncrypt(revision, keyLength);
    m_encrypted = true;
    int allowedFlags = wxPDF_PERMISSION_PRINT | wxPDF_PERMISSION_MODIFY |
                       wxPDF_PERMISSION_COPY  | wxPDF_PERMISSION_ANNOT;
    int protection = 192;
    protection += (permissions & allowedFlags);
    wxString ownerPswd = ownerPassword;
    if (ownerPswd.Length() == 0)
    {
      ownerPswd = wxPdfDocument::GetUniqueId(_T("wxPdfDoc"));
    }
    m_encryptor->GenerateEncryptionKey(userPassword, ownerPswd, protection);
  }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index