Check PDF Permissions

This guide checks the permission access available for a PDF document with the security package.

UniPDF can secure and encrypt PDF documents to prevent unauthorized access from printing or copying the documents.

Security handlers are used to control document security in the UniPDF SDK. Security handlers authorize users and assign various permissions to PDF documents.

PDF’s standard security handler accepts two passwords (user password and owner password) and assigns various permissions to PDF documents based on the passwords.

User Password: allows users to access a password-protected PDF based on the document owner’s permission.

Owner Password: grants full access to all the permissions of a password-protected PDF document. This includes the ability to change the document’s passwords and access permissions.

Permissions are the actions and access granted to the user and owner passwords. For example, A user with the user password can only open and read a PDF document, whereas a user with the owner password can open and download a PDF document.

You can modify the permissions with the Protect PDF guide.

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.

Clone the project repository

In your terminal, clone the 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

How it works

Lines 9-16 import the UniPDF packages and other required dependencies.

The init function in lines 18-25 authenticate your request with your UNIDOC_LICENSE_API_KEY.

The main function in lines 27-43 validates your input and passes it as arguments to the printAccessInfo function.This is where you get to define your regex patterns in the variable patterns and initialize a RectangleProp object to draw a black rectangular box over redacted text in a PDF.

Lines 45-93 define the printAccessInfo function, which takes the filePath and password(this is optional) as arguments. The printAccessInfo function reads the input PDF from the filepath, checks the available permissions with the checkAccessRights method and print the permissions to the terminal.

Run the code

Run this command to check the permissons access to a PDF. This will also get all the required dependencies to run the program.

#provide a password if the PDF is password-protected
go run pdf_check_permissions.go filepath password

Sample output

You will get the available permissions access to the input PDF on the terminal.

Input file test_file01.pdf
Access Permissions: 4294967295
--------
Printing allowed? - Yes
Full print quality (otherwise print in low res)? - Yes
Modifications allowed? - Yes
Allow extracting graphics? Yes
Can annotate? - Yes
Can fill forms? - Yes
Extract text, graphics for users with disabilities? - Yes

Got any Questions?

We're here to help you.