How to encrypt, password-protect and set restricted permissions on a PDF in Python

pip install cloudmersive-convert-api-client
from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.EditPdfApi(cloudmersive_convert_api_client.ApiClient(configuration))owner_password = 'owner_password_example' # str | Password of a owner (creator/editor) of the PDF file (required)user_password = 'user_password_example' # str | Password of a user (reader) of the PDF file (optional)input_file = '/path/to/file' # file | Input file to perform the operation on.encryption_key_length = 'encryption_key_length_example' # str | Possible values are \"128\" (128-bit RC4 encryption) and \"256\" (256-bit AES encryption).  Default is 256. (optional)allow_printing = true # bool | Set to false to disable printing through DRM.  Default is true. (optional)allow_document_assembly = true # bool | Set to false to disable document assembly through DRM.  Default is true. (optional)allow_content_extraction = true # bool | Set to false to disable copying/extracting content out of the PDF through DRM.  Default is true. (optional)allow_form_filling = true # bool | Set to false to disable filling out form fields in the PDF through DRM.  Default is true. (optional)allow_editing = true # bool | Set to false to disable editing in the PDF through DRM (making the PDF read-only).  Default is true. (optional)allow_annotations = true # bool | Set to false to disable annotations and editing of annotations in the PDF through DRM.  Default is true. (optional)allow_degraded_printing = true # bool | Set to false to disable degraded printing of the PDF through DRM.  Default is true. (optional)try:# Encrypt, password-protect and set restricted permissions on a PDFapi_response = api_instance.edit_pdf_set_permissions(owner_password, user_password, input_file, encryption_key_length=encryption_key_length, allow_printing=allow_printing, allow_document_assembly=allow_document_assembly, allow_content_extraction=allow_content_extraction, allow_form_filling=allow_form_filling, allow_editing=allow_editing, allow_annotations=allow_annotations, allow_degraded_printing=allow_degraded_printing)pprint(api_response)except ApiException as e:print("Exception when calling EditPdfApi->edit_pdf_set_permissions: %s\n" % e)

--

--

--

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How Much Does It Cost To Build a Website With Drupal

Ready for FREE vouchers for Microsoft Certifications?

Pi Protocol Weekly Updates — Week 6

Fintech Mobile App Development: Cost, Features, Technology Stack and More

Create a Cross Platform Mobile App With Flutter in Under 5 Minutes!

Usage of Docker in Test Automation

NFT Vision Hack x Rarible “Build on the Rarible Protocol”

Stock Analyses with PySpark

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

More from Medium

Generate a EAN-8 code barcode as PNG file in Python

Docker to the rescue

Watching webcam stream in terminal, using ascii characters & Python

Securing your Flask app: automatic SSL certificate and AJAX CSRF protection

A padlock icon over a minified JavaScript code