Enabling LTV To Signed File
This guide shows how to LTV enable the signatures in a signed PDF file, by adding a second revision to the document containing the validation data.
Before you begin
You should get your API key from your UniCloud account.
If this is your first time using UniPDF SDK, follow this guide to set up a local development environment.
Project setup
Clone the project repository
In your terminal, clone examples repository using the following command. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unipdf-examples.git
Then navigate to the signatures folder in the unipdf-examples directory.
cd unipdf-examples/signatures
Configure environment variables
Configure your license key using the following command: Replace the UNIDOC_LICENSE_API_KEY with your API credentials from your UniCloud account.
Linux/Mac
export UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE
Windows
set UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE
How it works
In the example code, the import section is used to import the necessary UniPDF packages and other Go libraries.
The init function initializes the program by setting the license key which are loaded in your system environment.
The main function defined in lines 33-100, does the LTV enabling of the signature. In lines 43-63, the certificate chain is loaded. Then in line 78, a new PdfAppender is created using appender, err := model.NewPdfAppender(reader). The certificate chain is LTV enabled using ltv.EnableAll(certChain) in line 89. Then the document is written to file using appender.WriteToFile(outputPath) in line 94.
Run the code
Use the following commands to run the code:
go run pdf_ltv_enable_signed_file.go <INPUT_PDF_PATH> <OUTPUT_PDF_PATH> [<EXTRA_CERTS.pem>]