![]() |
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
(Android™) 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.
// Important: Don't forget to include the call to System.loadLibrary // as shown at the bottom of this code sample. package com.test; import android.app.Activity; import com.chilkatsoft.*; import android.widget.TextView; import android.os.Bundle; public class SimpleActivity extends Activity { private static final String TAG = "Chilkat"; // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean success = false; CkPdf pdf = new CkPdf(); // Load a PDF to be signed. success = pdf.LoadFile("c:/someDir/my.pdf"); if (success == false) { Log.i(TAG, pdf.lastErrorText()); return; } // Options for signing are specified in JSON. CkJsonObject json = new CkJsonObject(); json.UpdateString("subFilter","/ETSI.CAdES.detached"); json.UpdateBool("signingCertificateV2",true); json.UpdateBool("signingTime",true); json.UpdateString("signingAlgorithm","pkcs"); json.UpdateString("hashAlgorithm","sha256"); // ----------------------------------------------------------- // The following JSON settings define the signature appearance. json.UpdateInt("page",1); json.UpdateString("appearance.y","top"); json.UpdateString("appearance.x","left"); json.UpdateString("appearance.fontScale","10.0"); json.UpdateString("appearance.text[0]","Digitally signed by: cert_cn"); json.UpdateString("appearance.text[1]","current_dt"); json.UpdateString("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. CkCert cert = new CkCert(); success = cert.LoadPfxFile("c:/myPfxFiles/myPdfSigningCert.pfx","pfxPassword"); if (success == false) { Log.i(TAG, 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) { Log.i(TAG, pdf.lastErrorText()); return; } // Sign the PDF, creating the output file. String outFilePath = "c:/someDir/mySigned.pdf"; success = pdf.SignPdf(json,outFilePath); if (success == false) { Log.i(TAG, pdf.lastErrorText()); return; } Log.i(TAG, "Success."); } static { System.loadLibrary("chilkat"); // Note: If the incorrect library name is passed to System.loadLibrary, // then you will see the following error message at application startup: //"The application <your-application-name> has stopped unexpectedly. Please try again." } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.