How to sign a pdf document with PDF-XChange Editor SDK

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
abt
User
Posts: 1
Joined: Wed Jul 09, 2025 8:28 pm

How to sign a pdf document with PDF-XChange Editor SDK

Post by abt »

My objective is to digitally sign a generated document.
I came across the operation op.document.addDigitalSignature in the documentation and intend to use the IOperation interface’s Do() method to pass the file, the certificate data and any needed data. Could you please confirm if this is the recommended approach for programmatically adding a digital signature?
Additionally, I’d like to display some information within the signed PDF, such as signature metadata, using an annotation or stamp. Is there a recommended way to programmatically add such visual elements to the document through the SDK? If it is possible, how to position this element in the document?
I’ve searched through the SDK documentation and forums but haven’t found a working example, so any clarification or reference would be highly helpful.
Thank you very much for your assistance.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2488
Joined: Thu Jun 30, 2005 4:11 pm

Re: How to sign a pdf document with PDF-XChange Editor SDK

Post by Vasyl - PDF-XChange »

Hi,

There is simple example how to digitally sign the pdf:

Code: Select all

PDFXEdit.IOperation op = pdfCtl.Inst.CreateOp(pdfCtl.Inst.Str2ID("op.document.addDigitalSignature"));
{
    PDFXEdit.CoAUX_Cab pr = op.Params.Root;
    pr["Input"].Add().v = pdfCtl.Doc;
    PDFXEdit.ICabNode opts = pr["Options"];

    // 1. specify the certificate
    // 1.1 certificate is from the store:

    //opts["Certificate"].v = "<cert_thumbprint>"; // string that contains the certificate's thumbprint, base64-encoded (lowercase!),
                                                 // when certificate is from the system's store or from the PFX file previously added in 'Digital IDs Manager' component
                                                 // (look to RibbonUI > Protect > Digital IDs)

    // OR: 1.2 certificate is from the file:
    opts["UseFileCertificate"].v = true;
    opts["FileCertificate"].v = "c:\\Test\\TestCert123.pfx";
    opts["CertificatePassword"].v = "123"; // when is empty then it may ask the user for the password to open the specified pfx file

    // 2. specify the signature-field to be signed

    // 2.1 use existing unsigned-signature field  
    opts["FieldMode"].v = 0; // use existing
    opts["FieldName"].v = "Signature1"; // existing signature-field name

    // OR: 2.2 create new signature-field  
    // opts["FieldMode"].v = 2; // create new signature field
    // opts["PageNumber"].v = 0; // first page
    // opts["SignatureBox"]["left"].v = 20.0;
    // opts["SignatureBox"]["right"].v = 130.0;
    // opts["SignatureBox"]["top"].v = 100.0;
    // opts["SignatureBox"]["bottom"].v = 60.0;

    // 3. save the signed document
    // opts["AutoSave"].v = true; // is 'true' by default, with 'false' the signing process will be postponed up to the moment 
                                                       // when document will be saved to the file
    // opts["DestinationFileName"].v = "c:\\test_signed.pdf"; // is empty by default and saves back to the source pdf
    // opts["AskDestinationFileName"].v = "true"; // is 'false' by default, with 'true' will ask the user where the signed doc needs to be saved
}

op.Do(); // sign the doc
HTH
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.