Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get PDF Signer Certs
See more PDF Signatures Examples
This example demonstrates how to validate the signatures in a PDF and also shows how to getChilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Pdf,
Chilkat.Cert,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pdf: TPdf;
sigInfo: TJsonObject;
numSignatures: Integer;
validated: Boolean;
cert: TCert;
i: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pdf := TPdf.Create;
// Load a PDF that has cryptographic signatures to be validated
success := pdf.LoadFile('qa_data/pdf/sign_testing_1/helloSigned2.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
sigInfo := TJsonObject.Create;
// Iterate over each signature and validate each.
numSignatures := pdf.NumSignatures;
validated := False;
cert := TCert.Create;
i := 0;
while i < numSignatures do
begin
validated := pdf.VerifySignature(i,sigInfo);
WriteLn('Signature ' + i + ' validated: ' + validated);
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
success := pdf.GetSignerCert(i,cert);
if (success <> False) then
begin
WriteLn('PDF signer certificate: ' + cert.SubjectDN);
end;
i := i + 1;
end;
WriteLn('Finished.');
pdf.Free;
sigInfo.Free;
cert.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.