implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
obj: OleVariant;
iRtn, iPermissions: Integer;
sInFile, sOutFile: string;
begin
OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName);
if not OpenDialog1.Execute then
begin
Exit;
end else
begin
sInFile := OpenDialog1.FileName;
sOutFile := ChangeFileExt(sInFile, '') + '_CanNot_Print_Copy_Edit.pdf';
end;
try
obj := CreateOleObject('PDFEncryptX.EncryptLib'); //Create object
except
on E: Exception do
begin
ShowMessage('Please install AzSDK PDF Encrypt ActiveX DLL first.');
Exit;
end;
end;
obj.SetLicenseKey('License Code'); //Set your license key
iRtn := obj.LoadFromFile(sInFile, ''); //Load PDF file
{
iRtn = 1: loaded successful
iRtn = 0: Can not Load
iRtn =-1: File not exist
}
//if load file successful, then get relational property.
if iRtn = 1 then
begin
if obj.IsEncrypted = 1 then //Encrypted PDF ?
edtEncrypted.Text := '1->YES'
else edtEncrypted.Text := '0->NO';
edtPage.Text := IntToStr(obj.PageCount); //Page count of PDF
edtSize.Text := IntToStr(obj.FileSize); //File size of PDF
end;
//Create Permissions: Can not to print, copy and edit.
iPermissions := obj.CreatePermissions(0, 0, 0, 1, 1, 1, 1, 1);
//Call Encrypt method
iRtn := obj.Encrypt(sOutFile, 2, iPermissions, '', '');
case iRtn of
0: edtResult.Text := '0->Encrypt failed';
1: edtResult.Text := '1->Encrypt successful';
2: edtResult.Text := '2->Ignore - file already encrypted';
end;
Obj := Unassigned;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
end.