Delete Pages from Word - Page Management API
PDF4me Delete Pages from Word enables you to remove specific pages or page ranges from Word documents with flexible page selection options. This API service processes Word files and deletes pages using range-based deletion (start page to end page), specific page number deletion (comma-separated lists), and combined deletion patterns. The API receives Word document content through REST API calls, utilizing Base64 encoding for secure transmission. With support for full control over page selection, document optimization, and content cleanup, this solution is ideal for document refinement, content management, and document preparation 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
- Flexible Page Selection: Delete pages by range, specific numbers, or combination of both
- Range-Based Deletion: Remove consecutive pages from start page to end page
- Specific Page Deletion: Remove individual pages using comma-separated page numbers
- Document Optimization: Clean up documents by removing unwanted content
- Format Preservation: Maintain original document formatting and structure
- Metadata Preservation: Keep document properties and custom metadata
- Validation: Automatic page number validation and error handling
- Culture Support: Locale-specific document processing
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All page deletion operations are performed through a single endpoint:
- Method: POST
- Endpoint:
office/ApiV2Word/DeletePages
REST API Parameters
Complete list of parameters for the Delete Pages from Word REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required. At least one page deletion parameter (startPage, endPage, or pageNumbers) must be provided.
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 | UEsDBBQABgAIAAAA... |
Optional Parameters (At least one required for page deletion)
| Parameter | Type | Description | Example |
|---|---|---|---|
| startPage | Integer | Start page number (1-based index). Page number to begin deleting from. Must be ≥ 1 and ≤ document page count. If only startPage provided, deletes from this page to end of document. Cannot be greater than endPage | 2 |
| endPage | Integer | End page number (1-based index). Page number to stop deleting at. Must be ≥ startPage and ≤ document page count. Range is inclusive (both start and end pages deleted). Can be combined with pageNumbers for complex deletion patterns | 5 |
| pageNumbers | String | Comma-separated list of specific page numbers to delete. Format: "1,3,4" or "1-3,5,7-9". Can be used alone or combined with startPage/endPage. Invalid page numbers are silently ignored. Example: "2,4,6,8" deletes pages 2, 4, 6, and 8 | "2,4,6" |
| cultureName | String | Culture code for document processing (e.g., "en-US", "de-DE", "fr-FR"). Default: null (no culture-specific processing). Affects document language and formatting | en-US |
Page Deletion Modes
The API supports multiple page deletion modes:
- Range Deletion: Use
startPageandendPageto delete consecutive pages - Specific Page Deletion: Use
pageNumbersto delete individual pages - Combined Deletion: Use both range and specific page parameters together
- Delete to End: Use only
startPageto delete from that page to document end
Note: All page numbers are 1-based (first page = 1, not 0). Page numbers are automatically validated against document page count.
Output
The PDF4me Delete Pages from Word 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 specified pages deleted, 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
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
const wordBytes = atob(data.document); // Decode Base64
// Save or process wordBytes
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) - At least one page deletion criteria required (
startPage,endPage, orpageNumbers) - Invalid Base64 encoding in
docContent - Invalid or corrupted Word document
startPagecannot be greater thanendPage- Invalid page numbers (out of document range)
- 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
- Page deletion failure
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 content
"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);
Page Deletion Examples
Understanding different page deletion patterns:
| Document Pages | startPage | endPage | pageNumbers | Result |
|---|---|---|---|---|
| 1,2,3,4,5 | 2 | 4 | - | Keeps: 1,5 |
| 1,2,3,4,5 | 3 | - | - | Keeps: 1,2 |
| 1,2,3,4,5 | - | - | "2,4" | Keeps: 1,3,5 |
| 1,2,3,4,5 | 2 | 3 | "5" | Keeps: 1,4 |
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 (Range Deletion):
{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"startPage": 2,
"endPage": 4
}
Specific Pages Example:
{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"pageNumbers": "2,4,6,8"
}
Advanced Example (Combined Deletion):
{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"startPage": 2,
"endPage": 5,
"pageNumbers": "7,9",
"cultureName": "en-US"
}
Code Samples
The PDF4me Delete Pages from Word 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
- Contract Cleanup: Remove signature pages and appendices from contract copies
- Legal Document Preparation: Delete confidential pages before client distribution
- Court Filing Optimization: Remove unnecessary pages to meet filing requirements
- Client Document Versions: Create clean versions by removing internal notes
Business & Enterprise Use Cases
- Proposal Optimization: Remove internal cost pages from client proposals
- Marketing Material Cleanup: Delete outdated content pages from current materials
- Presentation Preparation: Remove backup slides and notes from final presentations
- Client Deliverable Optimization: Create clean versions by removing internal references
Education & Research Use Cases
- Medical Report Cleanup: Remove sensitive patient information pages
- Research Document Optimization: Delete preliminary data from final reports
- Protocol Document Preparation: Remove internal review pages from published protocols
- Compliance Documentation: Clean up documents for regulatory submissions
Finance & Banking Use Cases
- Financial Report Cleanup: Remove detailed appendices from executive summaries
- Budget Document Optimization: Delete historical data pages from current budgets
- Audit Report Preparation: Remove sensitive internal pages before external distribution
- Regulatory Filing Cleanup: Optimize documents to meet submission requirements