Get Security Info
This guide will show you how to get information about locked or password-protected PDF documents. The program returns whether or not a PDF is encrypted and the encryption method used.
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. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unipdf-examples.git
Navigate to the security
folder in the unipdf-examples directory.
cd unipdf-examples/security
Configure environment variables
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
Lines 9-15
import the UniPDF packages and other required dependencies.
Lines 17-24
authenticate your request with your UNIDOC_LICENSE_API_KEY
with the init function.
The main function in lines 26-39
validates your input and passes it as an argument to the printSecurityInfo
function.
Lines 41-80
define the printSecurityInfo
function, which accepts inputPath as a parameter. The function checks if the input PDF is encrypted or not and the encryption method.
Run the code
Run this command to get security info about locked PDFs. This will also get all the required dependencies to run the program.
Sample output
You will get the locked PDF’s encryption status on the terminal.