Example code is for an older version of Toolkit, newer code is available.
<?php
// Copyright (c) 2021 ActivePDF, Inc.
// ActivePDF Toolkit 2016
// Example generated 02/27/21
?>
<?php
// Get current path
$strPath = dirname(__FILE__) . "\\";
// Instantiate Object
$oTK = new COM("APToolkit.Object");
// Toolkit can directly encrypt a PDF file
// There are 3 types of encryption that Toolkit supports
// 40-bit, 128-bit and AES
// !NOTE: Evaluation keys will append 'DEMO' to the start of the password
// !NOTE: These EncryptFile methods are deprecated in Toolkit 2016
// use the EncryptPDF instead
// To encrypt a file with 40-bit encryption
$intEncryptFile = $oTK->EncryptFile($strPath . "PDF.pdf", $strPath . "Encrypted-40.pdf", "UserPassword", "OwnerPassword", 1, 1, 0, 0);
if ($intEncryptFile != 0) {
Error("EncryptFile", $intEncryptFile);
}
// To encrypt a file with 128-bit encryption
$intEncryptFile128 = $oTK->EncryptFile128($strPath . "PDF.pdf", $strPath . "Encrypted-128.pdf", "UserPassword", "OwnerPassword", 1, 1, 0, 0, 1, 0, 1, 1);
if ($intEncryptFile128 != 0) {
Error("EncryptFile128", $intEncryptFile128);
}
// To encrypt a file with AES encryption
$intEncryptFileAES = $oTK->EncryptFileAES($strPath . "PDF.pdf", $strPath . "Encrypted-AES.pdf", "UserPassword", "OwnerPassword", 1, 1, 0, 0, 1, 0, 1, 1);
if ($intEncryptFileAES != 0) {
Error("EncryptFileAES", $intEncryptFileAES);
}
// Release Object
$oTK = null;
// Process Complete
echo "Done!";
// Error Handling
function Error($method, $outputCode) {
echo "Error in " . $method . ": " . $outputCode;
}
?>