Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final pdf = CkPdf();
// Load a PDF that has cryptographic signatures to be validated
try {
pdf.loadFile('qa_data/pdf/sign_testing_1/helloSigned2.pdf');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
final sigInfo = CkJsonObject();
// Iterate over each signature and validate each.
final numSignatures = pdf.numSignatures;
var validated = false;
final cert = CkCert();
var i = 0;
while (i < numSignatures) {
validated = true;
try {
pdf.verifySignature(i, sigInfo);
} on ChilkatException {
validated = false;
}
print('Signature $i validated: $validated');
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
try {
pdf.getSignerCert(i, cert);
print('PDF signer certificate: ${cert.subjectDN}');
} on ChilkatException {
// pdf.getSignerCert() failed; continue anyway.
}
i++;
}
print('Finished.');
}