THotPDF.AddLoadedSignedSignatureField Method

Adds a signature field that is ready to sign to a loaded document. The field carries a signature dictionary with reserved /ByteRange and /Contents space, so SignPDFWithPFX, PreparePDFForSigning and InsertSignatureHex can sign it once the document is saved. Together with BeginIncrementalUpdate this is how an already signed PDF receives a second signature

Declaration

function AddLoadedSignedSignatureField(PageIndex: Integer; X1, Y1, X2, Y2: Single;
  const AFieldName: AnsiString; ContentsBytes: Integer = 8192;
  const SubFilter: AnsiString = 'adbe.pkcs7.detached';
  const Reason: AnsiString = ''; const Location: AnsiString = '';
  const ContactName: AnsiString = ''): Integer;

Unit

HPDFDoc

Parameters

NamePurpose
PageIndexZero-based index of the loaded page that shows the signature widget
X1, Y1, X2, Y2Widget rectangle in PDF user space (points, origin at the bottom left); the width and height must be positive
AFieldNameName of the new signature field; it must not be empty and must not already exist in the document
ContentsBytesBytes reserved for the CMS signature (written as twice as many hex digits); it must hold the complete signature, including certificates and any timestamp token
SubFilterSignature format, for example adbe.pkcs7.detached or ETSI.CAdES.detached
Reason, Location, ContactNameOptional /Reason, /Location and /ContactInfo entries of the signature dictionary

Return value

Returns the index of the new form field, or -1 when PageIndex is out of range

Usage notes

Example

PDF := THotPDF.Create(nil);
try
  PDF.BeginIncrementalUpdate('Signed.pdf');
  PDF.AddLoadedSignedSignatureField(0, 300, 120, 500, 160, 'Approver', 8192,
    'adbe.pkcs7.detached', 'Approved');
  PDF.SaveIncrementalUpdate('Prepared.pdf');
finally
  PDF.Free;
end;
// Signs the reserved field; the first signature stays valid
THotPDF.SignPDFWithPFX('Prepared.pdf', 'SignedTwice.pdf', 'Signer.pfx', 'password');

Related APIs