DynaPDF Manual - Page 451
Previous Page 450 Index Next Page 452

Function Reference
Page 451 of 860
Although it is clear what these restrictions mean, it is complicated to figure out how these values
can be set from the available restriction flags.
The restriction flags alone cannot be used to set the properties above. The encryption filter must be
taken into account too. The algorithm below was developed via trial and error. It is not known
whether Adobe’s Acrobat behaves exactly in this way, but it seems to be pretty close.
Example (Delphi):
The following code snippet was copied from the Delphi PDF viewer example version 3. Note that at
time of writing this documentation, version 3 of the viewer example was not yet published.
The PDF file must be opened by OpenImportFile() or OpenImportBuffer() before this function can
be called.
procedure TFormDocInfo.LoadSecuritySettings;
var info: TPDFEncryptInfo;
begin
FillChar(info, sizeof(info), 0);
if FPDF.GetInIsEncrypted then begin
info.StructSize := sizeof(info);
if not FPDF.GetInEncryptionInfo(info) then begin
ShowMessage('Failed to load encryption settings!');
Exit;
end;
if info.HaveOpenPassword then
lbOpenPwd.Caption := 'Yes';
if info.HaveOwnerPassword then
lbOwnerPwd.Caption := 'Yes';
// Consider the unsafe property only if both passwords are set since the file can always be
// decrypted if one password is not set.
if info.HaveOpenPassword and info.HaveOwnerPassword then begin
if info.UnsafeOpenPwd then begin
lbOpenPwd.Caption := 'Yes (unsafe)';
lbOpenPwd.Hint
:= 'Unsafe means that DynaPDF can easily decrypt the file';
end;
if info.UnsafeOwnerPwd then begin
lbOwnerPwd.Caption := 'Yes (usafe)';
lbOwnerPwd.Hint
:= 'Unsafe means that DynaPDF can easily decrypt the file';
end;
end;
if info.Filter = kl40bit then begin
// rsPrint
if info.Restrictions and rsPrint <> 0 then
lbPrinting.Caption := 'Not Allowed';
// rsModify
if info.Restrictions and rsModify <> 0 then begin
lbChangeDoc.Caption
:= 'Not Allowed';
lbDocAssembly.Caption
:= 'Not Allowed';
lbPageExtraction.Caption := 'Not Allowed';
end;
// rsAddObj
if info.Restrictions and rsAddObj <> 0 then begin
lbCommenting.Caption
:= 'Not Allowed';
lbFillFormFields.Caption := 'Not Allowed';
lbSigning.Caption
:= 'Not Allowed';
lbTemplCreation.Caption
:= 'Not Allowed';
end;
end else begin
// rsPrint
if info.Restrictions and rsPrint <> 0 then
lbPrinting.Caption := 'Not Allowed'
else if (info.Filter >= kl128bitEx) and (info.Restrictions and rsPrintHighRes <> 0) then
Previous topic: GetInEncryptionFlags (obsolete), GetInEncryptionInfo
Next topic: GetInFieldCount