Append a New Page for Digital Signature

This guide will explain the process of appending a new page with a signature to a PDF document.

Sample Input

sample PDF file

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

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.





How it works

The import section in lines imports UniPDF packages and other necessary libraries. The init function gets the API key and sets it to the license license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)).

The main function is defined in lines 37-81. In lines 38-44, of the main function, the input path and output paths are parsed from the command line arguments. Then a new PdfReader is instantiated from the input file in lines 47-53. Using addPage(pdfReader), a new page is added to the document. Then a signature is added to the new document using addSignature(pdfReader, totalPage, outputPath) in line 75.

The addPage function is defined in lines 83-99. This function adds a new page to the document using a model.PdfWriter object. Then the new document is returned in a buffer.

The addSignature function adds a signature to a document. The generateSigKeys() function generates and returns a private/public key pair, which is then used in the previous function to sign the document.

Run the code

Run the code using the following command:

go run pdf_sign_new_page.go <INPUT_PDF_PATH> <OUTPUT_PDF_PATH>

Sample output

Page 1

Signed Doc Page1

Page 2

Signed Doc Page2

Got any Questions?

We're here to help you.