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.

Häufig gestellte Fragen

Wie verschlüssele ich eine PDF-Datei, um sensible Informationen zu schützen?

Um eine PDF-Datei zu verschlüsseln, können Sie die IronSecureDoc-API verwenden, die es Ihnen ermöglicht, sowohl Benutzer- als auch Eigentümerpasswörter festzulegen. Diese Passwörter helfen dabei, den Zugriff und die Berechtigungen zu kontrollieren, wie z. B. Drucken und Ausfüllen von Formularen, um die Sicherheit des Dokuments zu gewährleisten.

Welche Schritte sind bei der Verwendung der IronSecureDoc API zur PDF-Verschlüsselung erforderlich?

Zuerst ziehen Sie das IronSecureDoc Docker-Image und richten es nach Ihrem Hosting-Umfeld ein. Verwenden Sie dann die API, um Parameter für die Verschlüsselung festzulegen, z. B. Passwörter und Berechtigungen festlegen, und führen Sie den API-Aufruf aus, um ein gesichertes PDF zu erzeugen.

Wie kann ich die IronSecureDoc API testen, ohne Code zu schreiben?

Sie können die IronSecureDoc API mit Swagger testen. Greifen Sie auf die Swagger-UI zu, finden Sie den relevanten API-Endpunkt, geben Sie die erforderlichen Parameter ein und führen Sie die Anfrage aus, um die Antwort zu sehen und sicherzustellen, dass die API korrekt funktioniert.

Was sind Benutzer- und Eigentümerpasswörter in der PDF-Sicherheit?

In der PDF-Sicherheit erlaubt das Benutzerpasswort das Lesen des Dokuments, während das Eigentümerpasswort vollen Zugang gewährt, einschließlich der Änderung von Berechtigungen. Mit IronSecureDoc können Sie beide Arten von Passwörtern festlegen, um die Sicherheit des Dokuments zu erhöhen.

Kann ich mit IronSecureDoc ein PDF so konfigurieren, dass es PDF/A-konform ist?

Ja, die IronSecureDoc API enthält Parameter, die es Ihnen ermöglichen, das verschlüsselte PDF als PDF/A-3-konform zu speichern, einem Standard für die Langzeitarchivierung elektronischer Dokumente.

Welche Berechtigungen können mit der IronSecureDoc API gesteuert werden?

Mit der IronSecureDoc API können Sie Berechtigungen wie Drucken, Formulardaten ausfüllen, Inhaltsentnahme, Anmerkungen und Modifikationen steuern, um sicherzustellen, dass PDFs in einer Weise verwendet werden, die mit Ihren Sicherheitsrichtlinien übereinstimmt.

Wie kann ich die IronSecureDoc API mit einer Python-Anwendung integrieren?

Um die IronSecureDoc API mit Python zu integrieren, verwenden Sie die Bibliothek requests, um eine POST-Anfrage an den API-Endpunkt zu senden. Fügen Sie die erforderlichen Header, Parameter und Dateidaten in Ihre Anfrage ein, um Ihre PDF-Dateien zu verschlüsseln und zu verwalten.

Welche Parameter sind für die Verschlüsselung eines PDFs mit IronSecureDoc wesentlich?

Wesentliche Parameter sind die zu verschlüsselnde PDF-Datei, Benutzer- und Eigentümerpasswörter sowie Berechtigungen für Aktionen wie Drucken und Bearbeiten. Diese Parameter gewährleisten die Sicherheit des Dokuments und die Kontrolle über seine Verwendung.

Ist es möglich, Metadaten während der Verschlüsselung mit IronSecureDoc in einem PDF zu ändern?

Ja, Sie können PDF-Metadaten wie Autor, Titel und Betreff mit den optionalen Parametern der IronSecureDoc API ändern, sodass Sie die Informationen des Dokuments während des Verschlüsselungsprozesses anpassen können.

Welche Hosting-Anforderungen gibt es für das lokale Ausführen von IronSecureDoc?

IronSecureDoc kann lokal auf Windows-, Mac- oder Linux-Systemen gehostet werden. Befolgen Sie die spezifischen Einrichtungshandbücher für Ihr Betriebssystem, um eine korrekte Installation und den Betrieb des Dienstes sicherzustellen.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Version: 2024.10 gerade veröffentlicht