PDFtoolkit VCL
Edit, enhance, secure, merge, split, view, print PDF and AcroForms documents
Compatibility
Delphi C++Builder

How To Digitally Sign A PDF Document In Delphi

Learn to add a signature form field to a PDF document.
By V. Subhash

In September 2009, we introduced the ability to digitally sign PDF documents in PDFtoolkit.

In a PDF document, digital signatures are represented as signature form fields. Signature form fields can be either visible or invisible. Visible signature fields are usually accompanied by the scanned image of a signature of a real person and/or the seal of an organization.

When the requirement is simply to sign a PDF document, then a hidden signature field would be enough. A viewer application such as Adobe Reader would still be able to identify and validate the signature in the document. In this article, we will see a code example on how to create such a document.

The method to add a signature is TgtPDFDocument.AddSignature(). It has several overloads for this method. In the following code example, the overload requires:

  1. PFXFileName: AnsiString - Pathname of the PFX file containing the digital certificate. You will get this file from a Certification Authority (CA).
  2. PFXPassword: AnsiString - Password for the PFX file.
  3. Reason: AnsiString Text that needs to be identified as the "reason" for adding the digital signature. For example, you can specify it as "I agree."
  4. Location: AnsiString - Text that needs to be identified as the "location" where the digital signature was added to the document. For example, you can use the CPU host name or the physical address where the signature was added.
  5. ContactInfo: AnsiString - Text that needs to be identified as the "contact information" of the owner of the digital signature. This information can be useful for the recipient of the document to contact the owner of the signature.
  6. PageNumber: Integer - Number of the page where the digital signature is added.
  7. FieldName: AnsiString - Name for the signature form field representing the digital signature. If a name is not specified, the PDF document component will generate a name for it.
program TgtPDFDocument_AddSignature_Hidden;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  gtPDFDoc, gtExPDFDoc;

var
  gtPDFDocument1: TgtPDFDocument;
begin
  // Create a document object
  gtPDFDocument1 := TgtPDFDocument.Create(Nil);

  try
   begin

    // Load input document
    gtPDFDocument1.LoadFromFile('to_be_signed_doc.pdf');
    Writeln('Document opened.');

    // Add a hidden signature field to a page
    gtPDFDocument1.AddSignature(
        'F:\Downloads\subhash@gnostice.com-2010-03-04',
        '-- snipped --',
        'To demonstrate digital signing',
        'Bangalore',
        '+91.80.41.726.529',
        5,
        'fld_sig1');
    Writeln('Document signed.');

    gtPDFDocument1.SaveToFile('signed_doc.pdf');
    Writeln('Document saved.');

   end
  except on Err:Exception do
   begin
     Writeln('Sorry, an exception was raised. ');
     Writeln(Err.Classname + ':' + Err.Message);
   end;
  end;

  // Free resources
  gtPDFDocument1.Reset;

  // Destroy document object
  FreeAndNil(gtPDFDocument1);

  Writeln('Press Enter to exit.');
  Readln;
end.

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.