Skip to main content

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

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

ParameterTypeDescriptionExample
headerContentStringSimple header content (used with footerContent when isHtml/isHtmlMode control format)"Company Name"
footerContentStringSimple footer content"Page PAGE of NUMPAGES"
isHtmlBooleanWhether header/footer content is HTMLtrue
isHtmlModeBooleanUse HTML mode for content processingtrue
allPagesHeaderHtmlStringHeader HTML for all pages. Supports PAGE, NUMPAGES, SECTION, SECTIONPAGES"<div style='text-align: center;'>Company Name</div>"
firstPageHeaderHtmlStringHeader HTML for first page only"<div style='text-align: center;'>Title Page</div>"
evenPagesHeaderHtmlStringHeader HTML for even-numbered pages"<div style='text-align: right;'>Book Title</div>"
oddPagesHeaderHtmlStringHeader HTML for odd-numbered pages"<div style='text-align: left;'>Chapter Title</div>"
allPagesFooterHtmlStringFooter HTML for all pages"Page PAGE of NUMPAGES"
firstPageFooterHtmlStringFooter HTML for first page only"<div style='text-align: center;'>Confidential</div>"
evenPagesFooterHtmlStringFooter HTML for even pages"<div style='text-align: center;'>Page PAGE</div>"
oddPagesFooterHtmlStringFooter HTML for odd pages"<div style='text-align: center;'>Page PAGE</div>"

Optional Parameters (Typed header/footer)

ParameterTypeDescriptionExample
allPagesHeaderObjectTyped header content for all pages (HeaderFooterContentInUpdate)
firstPageHeaderObjectTyped header for first page
evenPagesHeader / oddPagesHeaderObjectTyped header for even/odd pages
allPagesFooter / firstPageFooter / evenPagesFooter / oddPagesFooterObjectTyped footer content per page type

Optional Parameters (General)

ParameterTypeDescriptionExample
cultureNameStringCulture code for document processing (e.g., "en-US", "fr-FR", "de-DE"). Default: null. Affects document language and formattingen-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 TypeDescriptionRequired Parameters
All PagesSame header/footer on all pagesallPagesHeaderHtml, allPagesFooterHtml (or typed allPagesHeader, allPagesFooter)
First PageDifferent header/footer on first pagefirstPageHeaderHtml, firstPageFooterHtml (or typed equivalents)
Even/Odd PagesDifferent headers/footers for even and odd pagesevenPagesHeaderHtml, 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

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:

  1. Check success; if true, extract the document field from the JSON response
  2. Decode the Base64 string to get the binary Word document data
  3. 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();

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

Complete C# implementation for updating headers and footers in Word documents:

Industry Use Cases & Applications

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

Get Help