Secure Document - Document Security API
PDF4me Secure Document enables you to add password protection and security restrictions to Word documents with comprehensive security controls and editing restrictions. This API service processes Word files and applies open password protection, document editing restrictions, read-only protection, comment-only access, form field editing, and revision tracking. The API receives Word document content through REST API calls, utilizing Base64 encoding for secure transmission. With full control over security levels and password requirements, this solution is ideal for confidential documents, collaborative editing, and document access control workflows.
Authenticating Your API Request
To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.
Key Features
- Password Protection: Add password requirements to open documents
- Document Protection: Restrict editing capabilities with various protection types
- Read-Only Security: Make documents read-only to prevent unauthorized editing
- Comment-Only Access: Allow only comments to be added or modified
- Form Field Editing: Restrict editing to form fields only
- Revision Tracking: Allow only tracked changes and revisions
- Combined Security: Apply both password protection and editing restrictions
- Flexible Access Control: Different security levels for different use cases
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All document security operations are performed through a single endpoint:
- Method: POST
- Endpoint:
office/ApiV2Word/ApplySecurity
REST API Parameters
Complete list of parameters for the Secure Document REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required. Password parameters are required when their corresponding security options are enabled.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| document* | Object | Document reference. Must contain Name (string) — Word file name with .docx extension | { "Name": "document.docx" } |
| docContent* | Base64 | Word document content encoded in Base64. Security settings are applied to this document. Must be valid Word document (.docx, .doc formats) | base64EncodedDocumentContent |
Optional Parameters (Security Settings)
| Parameter | Type | Description | Example |
|---|---|---|---|
| secureOnOpen | String | Enable password protection to open document. "yes" = Requires password to open, "no" = No password required to open (default). Requires secureOnOpenPassword when enabled | "yes" |
| secureOnOpenPassword | String | Password required to open the document. Required when secureOnOpen is "yes". Should be strong password (8+ characters). Case-sensitive | "SecurePass123!" |
| securityOptions | Object | Document protection options. Properties: protectionType (string: NoProtection, ReadOnly, AllowComments, AllowFormFields, AllowRevisions), protectionPassword (string). Required when protectionType is not "NoProtection" | { "protectionType": "ReadOnly", "protectionPassword": "EditPass456!" } |
Protection Type Options
The API provides different protection types for document editing restrictions:
| Protection Type | Description | Use Case |
|---|---|---|
| NoProtection | No editing restrictions (default) | Documents that can be freely edited |
| ReadOnly | Document cannot be edited, only viewed | Final documents, published reports |
| AllowComments | Only comments can be added/modified | Document review workflows |
| AllowFormFields | Only form fields can be edited | Fillable forms, surveys |
| AllowRevisions | Only tracked changes/revisions allowed | Collaborative editing with change tracking |
Security Configuration
Password Protection (Open Password)
- Purpose: Requires password to open the document
- When to Use: Confidential documents, sensitive information
- Requirement:
secureOnOpenPasswordmust be provided whensecureOnOpenis"yes" - Strength: Recommended 8+ characters with alphanumeric and special characters
Document Protection (Editing Restrictions)
- Purpose: Restricts editing capabilities while allowing document viewing
- When to Use: Collaborative editing, form distribution, review workflows
- Requirement:
securityOptions.protectionPasswordmust be provided whensecurityOptions.protectionTypeis not "NoProtection" - Flexibility: Can be combined with open password for dual-layer security
Output
The PDF4me Secure Document REST API returns different responses based on the processing mode. The API returns the Word document as a Base64-encoded string in JSON format, not as binary data.
- Success Response
- Asynchronous Processing
- Error Responses
- Response Format Details
Synchronous Processing (Default)
The API processes the request and returns:
Status Code: 200 OK
Content-Type: application/json
Response Body:
{
"document": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"fileName": "document.docx",
"success": true,
"errorMessage": null
}
Response Fields:
- document (string): The Word document with security settings applied, encoded as Base64 string
- fileName (string): The output Word file name
- success (boolean): Indicates whether the request succeeded
- errorMessage (string or null): Error details when success is false
How to Use:
- Extract the
documentfield from the JSON response (Base64) - Decode the Base64 string to get the binary Word document data
- Save or process the Word file as needed
- The document will require password(s) when opened in Word based on security settings
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
const wordBytes = atob(data.document); // Decode Base64
// Save or process wordBytes - document is password protected
Asynchronous Processing
Asynchronous behavior (202 Accepted with polling) is controlled by server configuration, not by a request body parameter. When enabled, the API may return a 202 status with a polling URL in the Location header. Poll the URL with GET requests until you receive 200 OK with the same response shape (document, fileName, success, errorMessage).
Error Responses
The API returns standard HTTP error codes with error details:
- Invalid request parameters
- Missing required fields (
documentwithName,docContent) - Password is required when
secureOnOpenis "yes" (secureOnOpenPassword) - Protection password is required in
securityOptionswhen protectionType is not "NoProtection" - Invalid Base64 encoding in
docContent - Invalid or corrupted Word document
- Invalid protection type
- Weak password (less than 8 characters recommended)
- Invalid or missing API key
- API key not properly Base64 encoded in Authorization header
- Missing
Authorization: Basicheader
- Server-side processing error
- Word document processing failure
- Error applying security settings
- Error loading document from bytes
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON, never binary Word data directly.
Response Structure:
{
"document": "string", // Base64-encoded Word document with security applied
"fileName": "string", // Output Word filename
"success": true,
"errorMessage": "string or null"
}
Content-Type Header:
- Success:
application/json - The Word document is embedded as a Base64 string within the JSON response
Why Base64?
- JSON-safe encoding for binary data
- Easy to transmit over HTTP
- Compatible with all programming languages
- Can be directly embedded in JSON without escaping issues
Decoding Base64 to Word Document:
JavaScript/Node.js:
const base64 = response.document;
const binary = atob(base64); // Browser
// OR
const binary = Buffer.from(base64, 'base64'); // Node.js
Python:
import base64
word_bytes = base64.b64decode(response['document'])
with open('output.docx', 'wb') as f:
f.write(word_bytes)
C#:
byte[] wordBytes = Convert.FromBase64String(response.document);
File.WriteAllBytes("output.docx", wordBytes);
Request Example
Header
Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY
Note:
- Get your API key from the PDF4me Dashboard
- The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
- Example: If your API key is
abc123, encode it to Base64 and useAuthorization: Basic YWJjMTIz
Payload
Basic Example (Password Protection Only):
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"secureOnOpen": "yes",
"secureOnOpenPassword": "SecurePass123!"
}
Advanced Example (Password + Read-Only Protection):
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"secureOnOpen": "yes",
"secureOnOpenPassword": "SecurePass123!",
"securityOptions": {
"protectionType": "ReadOnly",
"protectionPassword": "EditPass456!"
}
}
Comment-Only Protection Example:
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"secureOnOpen": "no",
"securityOptions": {
"protectionType": "AllowComments",
"protectionPassword": "ReviewPass789!"
}
}
Form Field Protection Example:
{
"document": { "Name": "form.docx" },
"docContent": "base64EncodedDocumentContent",
"secureOnOpen": "no",
"securityOptions": {
"protectionType": "AllowFormFields",
"protectionPassword": "FormPass2024!"
}
}
Code Samples
The PDF4me Secure Document REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- n8n
- Google Script
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
Industry Use Cases & Applications
- Legal & Professional Services
- Business & Enterprise
- Education & Research
- Finance & Banking
Legal & Professional Services Use Cases
- Confidential Client Documents: Apply password protection to sensitive legal documents
- Contract Security: Secure contracts with read-only protection for client review
- Legal Form Distribution: Apply form field protection to legal forms
- Document Review: Use comment-only protection for legal document review
Business & Enterprise Use Cases
- Proposal Security: Apply password protection to confidential proposals
- Client Document Review: Use comment-only protection for client document review
- Marketing Form Distribution: Apply form field protection to marketing forms
- Sales Document Collaboration: Use revision protection for sales document editing
Education & Research Use Cases
- Patient Document Security: Apply password protection to confidential patient documents
- Medical Report Protection: Secure medical reports with read-only protection
- Research Document Collaboration: Use revision protection for research document editing
- Academic and Institutional Documents: Secure syllabi, grants, and internal documents
Finance & Banking Use Cases
- Financial Report Security: Apply password protection to confidential financial reports
- Audit Document Protection: Secure audit documents with read-only protection
- Budget Form Distribution: Apply form field protection to budget forms
- Compliance Documentation: Use revision protection for compliance document editing