![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Sign PDF using PAdES-Baseline-BSee more PDF Signatures ExamplesPAdES-Baseline-B is the most basic, entry-level profile of the PDF Advanced Electronic Signatures (PAdES) standard. It means:
In short: Baseline-B = a standard PDF digital signature that ensures integrity and origin, but without time or revocation guarantees.
#include <C_CkPdfW.h> #include <C_CkJsonObjectW.h> #include <C_CkCertW.h> void ChilkatSample(void) { BOOL success; HCkPdfW pdf; HCkJsonObjectW json; HCkCertW cert; const wchar_t *outFilePath; success = FALSE; pdf = CkPdfW_Create(); // Load a PDF to be signed. success = CkPdfW_LoadFile(pdf,L"c:/someDir/my.pdf"); if (success == FALSE) { wprintf(L"%s\n",CkPdfW_lastErrorText(pdf)); CkPdfW_Dispose(pdf); return; } // Options for signing are specified in JSON. json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"subFilter",L"/ETSI.CAdES.detached"); CkJsonObjectW_UpdateBool(json,L"signingCertificateV2",TRUE); CkJsonObjectW_UpdateBool(json,L"signingTime",TRUE); CkJsonObjectW_UpdateString(json,L"signingAlgorithm",L"pkcs"); CkJsonObjectW_UpdateString(json,L"hashAlgorithm",L"sha256"); // ----------------------------------------------------------- // The following JSON settings define the signature appearance. CkJsonObjectW_UpdateInt(json,L"page",1); CkJsonObjectW_UpdateString(json,L"appearance.y",L"top"); CkJsonObjectW_UpdateString(json,L"appearance.x",L"left"); CkJsonObjectW_UpdateString(json,L"appearance.fontScale",L"10.0"); CkJsonObjectW_UpdateString(json,L"appearance.text[0]",L"Digitally signed by: cert_cn"); CkJsonObjectW_UpdateString(json,L"appearance.text[1]",L"current_dt"); CkJsonObjectW_UpdateString(json,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. cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"c:/myPfxFiles/myPdfSigningCert.pfx",L"pfxPassword"); if (success == FALSE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkPdfW_Dispose(pdf); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); return; } // Once we have the certificate object, tell the PDF object to use it for signing success = CkPdfW_SetSigningCert(pdf,cert); if (success == FALSE) { wprintf(L"%s\n",CkPdfW_lastErrorText(pdf)); CkPdfW_Dispose(pdf); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); return; } // Sign the PDF, creating the output file. outFilePath = L"c:/someDir/mySigned.pdf"; success = CkPdfW_SignPdf(pdf,json,outFilePath); if (success == FALSE) { wprintf(L"%s\n",CkPdfW_lastErrorText(pdf)); CkPdfW_Dispose(pdf); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); return; } wprintf(L"Success.\n"); CkPdfW_Dispose(pdf); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.