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
- Enable the COM extension and restart the web server or PHP-FPM service.
- Install and register the matching 32-bit or 64-bit build.
- Make sure the PHP process account can read the input and write the output.
- 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 thecom_dotnetsection ifnew COM()fails. - Release the object by assigning
nullwhen the request ends.
During evaluation, leave the placeholder license key in place. After purchase, replace it with the key from your email.