Sample code for 30+ languages & platforms
Unicode C++

Sign PDF using PAdES-Baseline-B

See more PDF Signatures Examples

PAdES-Baseline-B is the most basic, entry-level profile of the PDF Advanced Electronic Signatures (PAdES) standard.

It means:

  • A PDF contains a CMS/PKCS#7 detached signature over the document’s byte range.
  • /SubFilter must be ETSI.CAdES.detached.
  • The signer’s X.509 certificate is included inside the signature.
  • The signature uses recognized secure algorithms (e.g., SHA-256 with RSA/ECDSA).
  • It proves document integrity (no changes since signing) and signer authenticity (certificate identifies who signed).
  • It does not include time-stamps, revocation data (CRL/OCSP), or long-term validation information — those appear only in higher levels (PAdES-Baseline-T, -LT, -LTA).

In short: Baseline-B = a standard PDF digital signature that ensures integrity and origin, but without time or revocation guarantees.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkPdfW.h>
#include <CkJsonObjectW.h>
#include <CkCertW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkPdfW pdf;

    // Load a PDF to be signed.
    success = pdf.LoadFile(L"c:/someDir/my.pdf");
    if (success == false) {
        wprintf(L"%s\n",pdf.lastErrorText());
        return;
    }

    // Options for signing are specified in JSON.
    CkJsonObjectW json;

    json.UpdateString(L"subFilter",L"/ETSI.CAdES.detached");
    json.UpdateBool(L"signingCertificateV2",true);
    json.UpdateBool(L"signingTime",true);
    json.UpdateString(L"signingAlgorithm",L"pkcs");
    json.UpdateString(L"hashAlgorithm",L"sha256");

    // -----------------------------------------------------------
    // The following JSON settings define the signature appearance.
    json.UpdateInt(L"page",1);
    json.UpdateString(L"appearance.y",L"top");
    json.UpdateString(L"appearance.x",L"left");
    json.UpdateString(L"appearance.fontScale",L"10.0");
    json.UpdateString(L"appearance.text[0]",L"Digitally signed by: cert_cn");
    json.UpdateString(L"appearance.text[1]",L"current_dt");
    json.UpdateString(L"appearance.text[2]",L"Hello 123 ABC");

    // --------------------------------------------------------------
    // Load the signing certificate. (Use your own certificate.)
    // Note: There are other methods for using a certificate on an HSM (smartcard or token)
    // or from other sources, such as a cloud HSM, a Windows installed certificate,
    // or other file formats.
    CkCertW cert;
    success = cert.LoadPfxFile(L"c:/myPfxFiles/myPdfSigningCert.pfx",L"pfxPassword");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    // Once we have the certificate object, tell the PDF object to use it for signing
    success = pdf.SetSigningCert(cert);
    if (success == false) {
        wprintf(L"%s\n",pdf.lastErrorText());
        return;
    }

    // Sign the PDF, creating the output file.
    const wchar_t *outFilePath = L"c:/someDir/mySigned.pdf";
    success = pdf.SignPdf(json,outFilePath);
    if (success == false) {
        wprintf(L"%s\n",pdf.lastErrorText());
        return;
    }

    wprintf(L"Success.\n");
    }