Sample code for 30+ languages & platforms
Dart

Sign PDF with Invisible Signature

See more PDF Signatures Examples

Demonstrates how to sign a PDF with an invisible signature.

Note: This example requires Chilkat v9.5.0.85 or greater.

Chilkat Dart Downloads

Dart
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 to be signed.
  // The "hello.pdf" is available at https://chilkatsoft.com/hello.pdf
  try {
    pdf.loadFile('qa_data/pdf/hello.pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Options for signing are specified in JSON.
  final json = CkJsonObject();

  // In most cases, the signingCertificateV2 and signingTime attributes are required.
  json.updateInt('signingCertificateV2', 1);
  json.updateInt('signingTime', 1);

  // Indicate that the signature will be invisible.
  json.updateBool('invisibleSignature', true);

  // Load the signing certificate. (Use your own certificate.)
  final cert = CkCert();
  try {
    cert.loadPfxFile('qa_data/pfx/myPdfSigningCert.pfx', 'secret');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Tell the pdf object to use the certificate for signing.
  try {
    pdf.setSigningCert(cert);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    pdf.signPdf(json, 'qa_output/hello_signed.pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('PDF successfully signed with an invisible signature.');

  // An invisible signature has no appearance within the PDF document itself,
  // but Adobe Acrobat will indicate the document is signed in a toolbar, as shown here:
  // (image:https://example-code.com/images/invisible_signature.jpg/endImage)
}