Skip to main content

Optimize Document - Document Optimization API

PDF4me Optimize Document enables you to optimize Word documents for size and performance with three different compression levels and comprehensive optimization techniques. This API service processes Word files and reduces file size, compresses images, cleans up content, normalizes formatting, and removes personal information. The API receives Word document content through REST API calls, utilizing Base64 encoding for secure transmission. With support for Low, Medium, and High optimization levels achieving 0-90% file size reduction, this solution is ideal for document preparation, storage optimization, and performance improvement 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

  • Maximum Optimization: Max compression profile for maximum file size reduction
  • File Size Reduction: Achieve 80-90% file size reduction with Max optimization
  • Image Compression: Intelligent image optimization with quality preservation
  • Content Cleanup: Remove unused macros, comments, and hidden content
  • Formatting Normalization: Clean up redundant formatting and unused styles
  • Personal Information Removal: Remove author, manager, and company information
  • Font Optimization: Normalize fonts and remove unnecessary font properties
  • Compatibility Enhancement: Optimize documents for Word 2016 compatibility

REST API Endpoint

The PDF4me REST API uses standard HTTP methods to interact with resources. All document optimization operations are performed through a single endpoint:

  • Method: POST
  • Endpoint: office/ApiV2Word/OptimizeDocument

REST API Parameters

Complete list of parameters for the Optimize Document REST API. Parameters are organized by category for better understanding and implementation.

Important: Parameters marked with an asterisk (*) are required. Optimization level determines the aggressiveness of optimization techniques applied.

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. Original document is not modified - new optimized version createdUEsDBBQABgAIAAAA...

Optional Parameters

ParameterTypeDescriptionExample
optimizationLevelStringOptimization level (e.g. Low, Medium, Max). Max - Maximum compression (~80-90%). Controls aggressiveness of optimization techniques"Max"
wordVersionStringTarget Word version for compatibilitynull
cultureNameStringCulture code for document processing (e.g., "en-US", "de-DE", "fr-FR")en-US

Optimization Profile

The Max optimization profile provides maximum compression:

  • File Size Reduction: 80-90%
  • Image Quality: Optimized for size
  • Formatting: Aggressive cleanup
  • Comments: Removed
  • Revisions: Removed
  • Personal Info: Removed
  • Macros: Removed
  • Unused Styles: Removed
  • Hidden Content: Removed

Output

The PDF4me Optimize 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 optimized Word document with reduced file size, 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

Example (JavaScript):

const response = await fetch(url, options);
const data = await response.json();
const wordBytes = atob(data.document); // Decode Base64
// Save or process wordBytes

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 (Default Max Optimization):

{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"optimizationLevel": "Max"
}

Advanced Example (With Optional Fields):

{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"optimizationLevel": "Max",
"wordVersion": null,
"cultureName": "en-US"
}

Code Samples

The PDF4me Optimize 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 optimizing Word documents:

Industry Use Cases & Applications

Legal & Professional Services Use Cases

  • Document Distribution: Optimize legal documents for client distribution
  • Public Filing: Prepare documents for public court filings
  • Archive Storage: Optimize legal documents for long-term storage
  • Compliance Documents: Clean up documents for regulatory submissions

Get Help