Skip to main content

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

ParameterTypeDescriptionExample
document*ObjectDocument reference. Must contain Name (string) — Word file name with .docx extension{ "Name": "document.docx" }
docContent*Base64Word 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)

ParameterTypeDescriptionExample
secureOnOpenStringEnable password protection to open document. "yes" = Requires password to open, "no" = No password required to open (default). Requires secureOnOpenPassword when enabled"yes"
secureOnOpenPasswordStringPassword required to open the document. Required when secureOnOpen is "yes". Should be strong password (8+ characters). Case-sensitive"SecurePass123!"
securityOptionsObjectDocument 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 TypeDescriptionUse Case
NoProtectionNo editing restrictions (default)Documents that can be freely edited
ReadOnlyDocument cannot be edited, only viewedFinal documents, published reports
AllowCommentsOnly comments can be added/modifiedDocument review workflows
AllowFormFieldsOnly form fields can be editedFillable forms, surveys
AllowRevisionsOnly tracked changes/revisions allowedCollaborative 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: secureOnOpenPassword must be provided when secureOnOpen is "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.protectionPassword must be provided when securityOptions.protectionType is 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.

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:

  1. Extract the document field from the JSON response (Base64)
  2. Decode the Base64 string to get the binary Word document data
  3. Save or process the Word file as needed
  4. 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

Request Example

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 use Authorization: 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# (CSharp) Sample

Complete C# implementation for securing Word documents:

Industry Use Cases & Applications

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

Get Help