![]() |
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
(PureBasic) 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.
IncludeFile "CkCert.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkPdf.pb" Procedure ChilkatExample() success.i = 0 pdf.i = CkPdf::ckCreate() If pdf.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load a PDF to be signed. success = CkPdf::ckLoadFile(pdf,"c:/someDir/my.pdf") If success = 0 Debug CkPdf::ckLastErrorText(pdf) CkPdf::ckDispose(pdf) ProcedureReturn EndIf ; Options for signing are specified in JSON. json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"subFilter","/ETSI.CAdES.detached") CkJsonObject::ckUpdateBool(json,"signingCertificateV2",1) CkJsonObject::ckUpdateBool(json,"signingTime",1) CkJsonObject::ckUpdateString(json,"signingAlgorithm","pkcs") CkJsonObject::ckUpdateString(json,"hashAlgorithm","sha256") ; ----------------------------------------------------------- ; The following JSON settings define the signature appearance. CkJsonObject::ckUpdateInt(json,"page",1) CkJsonObject::ckUpdateString(json,"appearance.y","top") CkJsonObject::ckUpdateString(json,"appearance.x","left") CkJsonObject::ckUpdateString(json,"appearance.fontScale","10.0") CkJsonObject::ckUpdateString(json,"appearance.text[0]","Digitally signed by: cert_cn") CkJsonObject::ckUpdateString(json,"appearance.text[1]","current_dt") CkJsonObject::ckUpdateString(json,"appearance.text[2]","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.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCert::ckLoadPfxFile(cert,"c:/myPfxFiles/myPdfSigningCert.pfx","pfxPassword") If success = 0 Debug CkCert::ckLastErrorText(cert) CkPdf::ckDispose(pdf) CkJsonObject::ckDispose(json) CkCert::ckDispose(cert) ProcedureReturn EndIf ; Once we have the certificate object, tell the PDF object to use it for signing success = CkPdf::ckSetSigningCert(pdf,cert) If success = 0 Debug CkPdf::ckLastErrorText(pdf) CkPdf::ckDispose(pdf) CkJsonObject::ckDispose(json) CkCert::ckDispose(cert) ProcedureReturn EndIf ; Sign the PDF, creating the output file. outFilePath.s = "c:/someDir/mySigned.pdf" success = CkPdf::ckSignPdf(pdf,json,outFilePath) If success = 0 Debug CkPdf::ckLastErrorText(pdf) CkPdf::ckDispose(pdf) CkJsonObject::ckDispose(json) CkCert::ckDispose(cert) ProcedureReturn EndIf Debug "Success." CkPdf::ckDispose(pdf) CkJsonObject::ckDispose(json) CkCert::ckDispose(cert) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.