Update Headers and Footers - Header Management API
PDF4me Update Headers and Footers enables you to add or modify headers and footers in Word documents with comprehensive HTML content support and professional styling options. This API service processes Word files and applies headers and footers to different page layouts including first page, even/odd pages, and all pages with automatic application of professional default styling, HTML content processing, and flexible page-specific formatting. The API receives Word document content through REST API calls, utilizing Base64 encoding for secure transmission. With support for page number fields (PAGE, NUMPAGES, SECTION, SECTIONPAGES), HTML formatting, and automatic professional styling, this solution is ideal for document branding, page numbering, and professional document presentation 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
- Multiple Page Types: Support for all pages, first page, even/odd pages
- HTML Content Support: Rich HTML content with professional styling
- Automatic Styling: Professional default styling for plain text content
- Page Number Fields: Support for PAGE, NUMPAGES, SECTION, SECTIONPAGES
- Flexible Layout: Different headers/footers for different page types
- Culture Support: Locale-specific document processing
- Format Preservation: Maintains original document structure
- Professional Appearance: Automatic application of professional styling
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All header and footer update operations are performed through a single endpoint:
- Method: POST
- Endpoint:
office/ApiV2Word/UpdateHeadersAndFooters
REST API Parameters
Complete list of parameters for the Update Headers and Footers REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required. Advanced parameters provide fine-grained control over page-specific headers and footers.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| document* | Object | Document descriptor. Must include Name (string): output Word file name with .docx extension | { "Name": "document.docx" } |
| docContent* | Base64 | Word document content encoded in Base64. Headers and footers are added to this document. Must be valid Word document (.docx, .doc formats) | base64EncodedDocumentContent |
Optional Parameters (Header/Footer HTML)
| Parameter | Type | Description | Example |
|---|---|---|---|
| headerContent | String | Simple header content (used with footerContent when isHtml/isHtmlMode control format) | "Company Name" |
| footerContent | String | Simple footer content | "Page PAGE of NUMPAGES" |
| isHtml | Boolean | Whether header/footer content is HTML | true |
| isHtmlMode | Boolean | Use HTML mode for content processing | true |
| allPagesHeaderHtml | String | Header HTML for all pages. Supports PAGE, NUMPAGES, SECTION, SECTIONPAGES | "<div style='text-align: center;'>Company Name</div>" |
| firstPageHeaderHtml | String | Header HTML for first page only | "<div style='text-align: center;'>Title Page</div>" |
| evenPagesHeaderHtml | String | Header HTML for even-numbered pages | "<div style='text-align: right;'>Book Title</div>" |
| oddPagesHeaderHtml | String | Header HTML for odd-numbered pages | "<div style='text-align: left;'>Chapter Title</div>" |
| allPagesFooterHtml | String | Footer HTML for all pages | "Page PAGE of NUMPAGES" |
| firstPageFooterHtml | String | Footer HTML for first page only | "<div style='text-align: center;'>Confidential</div>" |
| evenPagesFooterHtml | String | Footer HTML for even pages | "<div style='text-align: center;'>Page PAGE</div>" |
| oddPagesFooterHtml | String | Footer HTML for odd pages | "<div style='text-align: center;'>Page PAGE</div>" |
Optional Parameters (Typed header/footer)
| Parameter | Type | Description | Example |
|---|---|---|---|
| allPagesHeader | Object | Typed header content for all pages (HeaderFooterContentInUpdate) | — |
| firstPageHeader | Object | Typed header for first page | — |
| evenPagesHeader / oddPagesHeader | Object | Typed header for even/odd pages | — |
| allPagesFooter / firstPageFooter / evenPagesFooter / oddPagesFooter | Object | Typed footer content per page type | — |
Optional Parameters (General)
| Parameter | Type | Description | Example |
|---|---|---|---|
| cultureName | String | Culture code for document processing (e.g., "en-US", "fr-FR", "de-DE"). Default: null. Affects document language and formatting | en-US |
HTML Content Support
The API supports HTML content in all header and footer parameters:
- HTML Tags: Standard HTML tags (div, span, p, b, i, u, etc.)
- CSS Styling: Inline CSS styles for formatting
- Plain Text: Plain text automatically receives professional default styling
- Mixed Content: Combine HTML and plain text as needed
Default Styling for Plain Text:
- Headers: Left alignment, border-bottom, 10px font
- Footers: Center alignment, border-top, 9px font
Page Layout Options
The API supports different page layouts for headers and footers:
| Layout Type | Description | Required Parameters |
|---|---|---|
| All Pages | Same header/footer on all pages | allPagesHeaderHtml, allPagesFooterHtml (or typed allPagesHeader, allPagesFooter) |
| First Page | Different header/footer on first page | firstPageHeaderHtml, firstPageFooterHtml (or typed equivalents) |
| Even/Odd Pages | Different headers/footers for even and odd pages | evenPagesHeaderHtml, oddPagesHeaderHtml, evenPagesFooterHtml, oddPagesFooterHtml (or typed equivalents) |
Output
The PDF4me Update Headers and Footers REST API returns a JSON response. On success the API returns the Word document as a Base64-encoded string in the document field (ApiV2WordApiCallRes), not as binary data.
- Success Response
- Error Responses
- Response Format Details
Success Response
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 updated headers and footers, encoded as Base64
- fileName (string): The output Word file name
- success (boolean): Whether the operation succeeded
- errorMessage (string): Error message if success is false; otherwise null
How to Use:
- Check
success; if true, extract thedocumentfield from the JSON response - Decode the Base64 string to get the binary Word document data
- Save or process the Word file using
fileName
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
if (!data.success) throw new Error(data.errorMessage);
const base64 = data.document;
const binary = atob(base64);
const blob = new Blob([binary], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = data.fileName;
a.click();
Error Responses
The API returns standard HTTP error codes with error details:
- Invalid request parameters
- Missing required fields (
document,docContent) - Invalid Base64 encoding in
docContent - Invalid or corrupted Word document
- Invalid HTML content provided
- Invalid culture name provided
- Page number field not supported (use PAGE, NUMPAGES, SECTION, SECTIONPAGES)
- 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 updating headers and footers
- Error loading document from bytes
- Error converting document to bytes
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON with Base64-encoded Word document content, never binary Word data directly.
Response Structure (ApiV2WordApiCallRes):
{
"document": "string", // Base64-encoded Word document content
"fileName": "string", // Output Word file name
"success": true,
"errorMessage": 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
Processing the Response:
JavaScript/Node.js:
const response = await fetch(url, options);
const data = await response.json();
const base64 = data.document;
const binary = atob(base64); // Browser
// OR
const binary = Buffer.from(base64, 'base64'); // Node.js
Python:
import base64
response_data = response.json()
word_bytes = base64.b64decode(response_data['document'])
with open('output.docx', 'wb') as f:
f.write(word_bytes)
C#:
var response = JsonConvert.DeserializeObject<UpdateHeadersFootersResponse>(jsonResponse);
byte[] wordBytes = Convert.FromBase64String(response.document);
File.WriteAllBytes(response.fileName, 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 (All Pages Header and Footer):
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"allPagesHeaderHtml": "<div style='text-align: center;'>Company Name</div>",
"allPagesFooterHtml": "Page PAGE of NUMPAGES",
"cultureName": "en-US"
}
Advanced Example (First Page + Even/Odd Pages):
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"firstPageHeaderHtml": "<div style='text-align: center;'>Title Page</div>",
"firstPageFooterHtml": "<div style='text-align: center;'>Confidential</div>",
"oddPagesHeaderHtml": "<div style='text-align: left;'>Chapter Title</div>",
"evenPagesHeaderHtml": "<div style='text-align: right;'>Book Title</div>",
"oddPagesFooterHtml": "<div style='text-align: center;'>Page PAGE</div>",
"evenPagesFooterHtml": "<div style='text-align: center;'>Page PAGE</div>",
"cultureName": "en-US"
}
HTML Content Example:
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"allPagesHeaderHtml": "<div style='text-align: center; color: #333; font-size: 12px; border-bottom: 1px solid #ccc; padding-bottom: 5px;'>Company Name | Department</div>",
"allPagesFooterHtml": "<div style='text-align: center; color: #666; font-size: 9px; border-top: 1px solid #ccc; padding-top: 5px;'>Page PAGE of NUMPAGES | © 2024 Company Name</div>",
"cultureName": "en-US"
}
Plain Text Example (headerContent/footerContent):
{
"document": { "Name": "document.docx" },
"docContent": "base64EncodedDocumentContent",
"headerContent": "Company Name",
"footerContent": "Page PAGE of NUMPAGES",
"cultureName": "en-US"
}
Code Samples
The PDF4me Update Headers and Footers 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
C# (CSharp) Sample
Complete C# implementation for updating headers and footers in Word documents:
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 Headers: Add confidentiality notices and legal disclaimers
- Court Documents: Include case numbers and filing information
- Legal Briefs: Add attorney information and case details
- Compliance Reports: Include regulatory information and dates
Business & Enterprise Use Cases
- Document Branding: Add company logos and headers to business documents
- Report Headers: Add consistent headers and footers to generated reports
- Proposals: Include company information and page numbering
- Corporate Communications: Apply consistent headers and footers across documents
Education & Research Use Cases
- Academic Papers: Add institution information and course details
- Research Reports: Include funding information and acknowledgments
- Medical and Research Documents: Add study information, ethics approval, and protocol details
- Administrative Documents: Include department and contact information
Finance & Banking Use Cases
- Financial Reports: Add company information and report dates
- Audit Documents: Include auditor information and report numbers
- Regulatory Filings: Add regulatory compliance information
- Investment Documents: Include risk disclaimers and legal notices