The PHP example uses the COM extension on Windows. Enable extension=com_dotnet in php.ini and run PHP with the same bitness as the registered DLL.

The script creates the component, sets the license key, loads a PDF and writes an encrypted copy.

Before you start

  1. Enable the COM extension and restart the web server or PHP-FPM service.
  2. Install and register the matching 32-bit or 64-bit build.
  3. Make sure the PHP process account can read the input and write the output.
  4. Call SetLicenseKey() before processing.

Complete example

PHP
<?php
  //Create object
  $obj = new COM('PDFEncryptX.EncryptLib') or die("Start PDFEncryptX.EncryptLibfailed");

  $obj->SetLicenseKey("License Code");  //Set your license key

  if ( 1 == $obj->LoadFromFile("../PDFEncryptX.pdf", "") )  //Load PDF file
  {
    //Create Permissions: Can not to print, copy and edit.
    iPermissions = $obj->CreatePermission(0, 0, 0, 1, 1, 1, 1, 1)

    //Call encrypt() method
    if ( 1 == $obj->Encrypt("../PDFEncryptX_CanNot_Print_Copy_Edit.pdf", 2, iPermissions, "", "") )
    {
      echo "Encrypt successful." ;
    }
  }

  $obj = null;
?>

How it works

  • COM support is Windows-only.
  • Check phpinfo() for the com_dotnet section if new COM() fails.
  • Release the object by assigning null when the request ends.
During evaluation, leave the placeholder license key in place. After purchase, replace it with the key from your email.