How to Encrypt/Add Password & Permissions to PDF Files

This article was translated from English: Does it need improvement?
Translated
View the article in English

Securing PDF files with passwords and specific permissions is vital for protecting sensitive documents from unauthorized access and manipulation. The [POST] Encrypt/Add Password & Permissions API from IronSecure Doc provides an efficient way to encrypt PDF files with user and owner passwords while configuring permissions for printing, form filling, annotations, and more. This API ensures that the PDF is fully protected and access is controlled, making it ideal for legal, financial, or personal documents.

Pull and Start IronSecureDoc

If you don't have IronSecureDoc running yet, please follow the links below to get it set up:

Host Locally Deploy to Cloud

The [POST] Encrypt/Add Password & Permissions API

The [POST] Encrypt/Add Password & Permissions API allows you to add security layers to PDF documents by encrypting them with passwords and setting specific permissions for various operations. Whether it's granting read access, allowing form filling, or disabling printing, this API gives you control over how your PDF files are accessed and modified.

Swagger

Swagger offers a user-friendly interface to test this API interactively. You can use it to send test requests and receive responses without writing code, making it a great tool for developers.

Steps to Redact Text with Swagger

  1. Access the Swagger UI:

If your API server is running locally, you can access Swagger by navigating to http://localhost:8080/swagger/index.html in your web browser.

Swagger docs

  1. Locate the API:

Find the [POST] /v1/document-services/pdfs/encrypt API, which corresponds to Encrypt/Add Password & Permissions.

Redact text

  1. Input Parameters:

Provide the required parameters for the API. You can upload a sample PDF file and specify the desired permissions.

  1. Upload PDF File:

In the request body, upload a PDF file as pdf_file and define the necessary permissions, such as allowing or restricting printing, form filling, and content extraction.

  1. Execute the Request:

Once all parameters are set, click "Execute" to send the request. The response will return the encrypted PDF with the specified security settings.

  1. Check the Output PDF:

Type in 'password' to view the PDF content.


Understanding Input Parameters

The API requires specific parameters to encrypt the PDF and assign permissions. Below is a breakdown of both required and optional parameters:

Required Parameters

Name Data Type Description
pdf_file application/pdf The PDF file you want to encrypt.
allow_extracting_content boolean Indicate whether content extraction is allowed.
allow_form_filling boolean Indicate whether form filling is allowed.
allow_annotations boolean Indicate whether annotations are allowed.
allow_printing boolean Indicate whether printing is allowed.
allow_modifications boolean Indicate whether modifications are allowed.
new_owner_password string The new owner password for the PDF, which grants full access and the ability to change permissions.

Optional Parameters

Name Data Type Description
user_password string The current user password, required if the PDF has a user password to grant read access.
owner_password string The current owner password, required if the PDF has an owner password to grant full access.
new_user_password string The new user password for read access.
save_as_pdfa boolean Save the PDF as PDF/A-3 compliant.
save_as_pdfua boolean Save the PDF as PDF/UA compliant.
author string Set the PDF metadata Author property.
title string Set the PDF metadata Title property.
subject string Set the PDF metadata Subject property.

API Integration: Python Example

Once you're familiar with the input parameters, you can call the API using Python or any other preferred language. Below is an example of how to integrate this API using Python.

import requests

# Endpoint URL
url = 'http://localhost:8080/v1/document-services/pdfs/encrypt'

# Headers with metadata information
headers = {
    'accept': '*/*',
    'author': 'IronSoftware',
    'title': 'ENCRYPTION DEMO 2024',
    'subject': 'DEMO EXAMPLE'
}

# Files to be sent in the request
files = {
    'pdf_file': ('sample.pdf', open('sample.pdf', 'rb'), 'application/pdf')
}

# Parameters for encryption and permissions
data = {
    'allow_extracting_content': 'true',
    'allow_form_filling': 'true',
    'allow_annotations': 'false',
    'allow_printing': 'false',
    'allow_modifications': 'true',
    'new_owner_password': 'password',
    'new_user_password': 'password',
    'save_as_pdfa': 'false',
    'save_as_pdfua': 'false'
}

# Send POST request with parameters
response = requests.post(url, headers=headers, files=files, data=data)

# Save the encrypted PDF to file system
with open('sample_encrypted.pdf', 'wb') as f:
    f.write(response.content)

print('PDF encrypted successfully.')
import requests

# Endpoint URL
url = 'http://localhost:8080/v1/document-services/pdfs/encrypt'

# Headers with metadata information
headers = {
    'accept': '*/*',
    'author': 'IronSoftware',
    'title': 'ENCRYPTION DEMO 2024',
    'subject': 'DEMO EXAMPLE'
}

# Files to be sent in the request
files = {
    'pdf_file': ('sample.pdf', open('sample.pdf', 'rb'), 'application/pdf')
}

# Parameters for encryption and permissions
data = {
    'allow_extracting_content': 'true',
    'allow_form_filling': 'true',
    'allow_annotations': 'false',
    'allow_printing': 'false',
    'allow_modifications': 'true',
    'new_owner_password': 'password',
    'new_user_password': 'password',
    'save_as_pdfa': 'false',
    'save_as_pdfua': 'false'
}

# Send POST request with parameters
response = requests.post(url, headers=headers, files=files, data=data)

# Save the encrypted PDF to file system
with open('sample_encrypted.pdf', 'wb') as f:
    f.write(response.content)

print('PDF encrypted successfully.')
PYTHON

Steps Explained:

  • Load the PDF: The PDF file to be encrypted is loaded from the local file system.
  • Set Encryption Parameters: Define permissions like allowing printing, form filling, and content extraction, as well as setting new passwords.
  • Call the API: The [POST] Encrypt/Add Password & Permissions API is called, passing the necessary parameters.
  • Save the Result: The encrypted PDF is saved as a new file.

The PDF file is encrypted as shown below. Type in 'password' to view the PDF content.

Questions Fréquemment Posées

Comment puis-je chiffrer un fichier PDF pour protéger des informations sensibles ?

Pour chiffrer un fichier PDF, vous pouvez utiliser l'API IronSecureDoc, qui vous permet de définir des mots de passe utilisateur et propriétaire. Ces mots de passe aident à contrôler l'accès et les permissions, comme l'impression et le remplissage de formulaires, assurant la sécurité du document.

Quelles sont les étapes nécessaires pour utiliser l'API IronSecureDoc pour le chiffrement PDF ?

Tout d'abord, téléchargez l'image Docker IronSecureDoc et configurez-la en fonction de votre environnement d'hébergement. Ensuite, utilisez l'API pour spécifier les paramètres de chiffrement, tels que la configuration des mots de passe et des autorisations, et exécutez l'appel API pour produire un PDF sécurisé.

Comment puis-je tester l'API IronSecureDoc sans écrire de code ?

Vous pouvez tester l'API IronSecureDoc en utilisant Swagger. Accédez à l'interface utilisateur de Swagger, trouvez le point d'extrémité API pertinent, saisissez les paramètres nécessaires et exécutez la demande pour voir la réponse et vous assurer que l'API fonctionne correctement.

Quels sont les mots de passe utilisateur et propriétaire dans la sécurité PDF ?

Dans la sécurité PDF, le mot de passe utilisateur permet de lire le document, tandis que le mot de passe propriétaire accorde un accès complet, y compris la modification des autorisations. Avec IronSecureDoc, vous pouvez définir les deux types de mots de passe pour renforcer la sécurité du document.

Puis-je configurer un PDF pour être conforme PDF/A en utilisant IronSecureDoc ?

Oui, l'API IronSecureDoc inclut des paramètres qui vous permettent d'enregistrer le PDF chiffré comme conforme PDF/A-3, ce qui est un standard pour la préservation à long terme des documents électroniques.

Quelles permissions peuvent être contrôlées avec l'API IronSecureDoc ?

En utilisant l'API IronSecureDoc, vous pouvez contrôler les permissions telles que l'impression, le remplissage de formulaires, l'extraction de contenu, les annotations et les modifications, assurant ainsi que les PDF sont utilisés d'une manière conforme à vos politiques de sécurité.

Comment puis-je intégrer l'API IronSecureDoc avec une application Python ?

Pour intégrer l'API IronSecureDoc avec Python, utilisez la bibliothèque requests pour envoyer une requête POST au point d'extrémité de l'API. Incluez les en-têtes nécessaires, les paramètres et les données de fichier dans votre demande pour chiffrer et gérer vos fichiers PDF.

Quels paramètres sont essentiels pour chiffrer un PDF à l'aide d'IronSecureDoc ?

Les paramètres essentiels incluent le fichier PDF à chiffrer, les mots de passe utilisateur et propriétaire, et les autorisations pour des actions telles que l'impression et la modification. Ces paramètres assurent la sécurité du document et le contrôle de son utilisation.

Est-il possible de modifier les métadonnées dans un PDF lors du chiffrement avec IronSecureDoc ?

Oui, vous pouvez modifier les métadonnées PDF telles que l'auteur, le titre et le sujet en utilisant les paramètres facultatifs de l'API IronSecureDoc, vous permettant de personnaliser les informations du document lors du processus de chiffrement.

Quelles sont les exigences d'hébergement pour l'exécution locale d'IronSecureDoc ?

IronSecureDoc peut être hébergé localement sur des systèmes Windows, Mac ou Linux. Suivez les tutoriels d'installation spécifiques à votre système d'exploitation pour assurer une installation et un fonctionnement corrects du service.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Version : 2024.10 vient de sortir