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 Developer Tools
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.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

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

XtremeDocumentStudio .NET

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

PDFOne (for Java™)

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

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

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

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).