Skip to main content

Add Image Header Footer - Excel API

PDF4me Add Image Header Footer enables you to add customizable image headers and footers to Excel documents with comprehensive positioning and formatting control. This API service processes Excel files and adds image headers or footers with placement control (header/footer), horizontal alignment (left, center, right), worksheet targeting (specific sheets or all sheets), and page margins in centimeters. The API receives Excel document content and image data through REST API calls, utilizing Base64 encoding for secure transmission. With support for PNG, JPG, JPEG, and GIF image formats, this solution is ideal for corporate branding, professional reports, and document automation workflows.

Authenticating Your API Request

Include your API key in the request to authenticate with the PDF4me REST API.

Key Features

  • Header or Footer Placement: Choose whether to place images in document header or footer sections
  • Position Control: Align images left, center, or right within header/footer area
  • Worksheet Targeting: Apply images to specific worksheets by name or index, or all worksheets
  • Margin Customization: Configure top, bottom, left, and right page margins in centimeters
  • Image Format Support: PNG, JPG, JPEG, and GIF formats

REST API Endpoint

The PDF4me REST API uses standard HTTP methods to interact with resources. All image header/footer operations for Excel are performed through a single endpoint:

  • Method: POST
  • Endpoint: office/ApiV2Excel/ExcelAddImageHeaderFooter

REST API Parameters

Important: Parameters marked with an asterisk (*) are required. All requests use document, docContent, imageContent (root level), and addImageHeaderFooterToExcelAction. Other options are properties of the action object.

Required Parameters (root level)

ParameterTypeDescriptionExample
document*ObjectDocument reference. Must contain Name (string) — Excel file name with .xlsx or .xls extension{ "Name": "data.xlsx" }
docContent*String (Base64)Excel document content encoded in Base64UEsDBBQABgAIAAAA...
imageContent*String (Base64)Image file content encoded in Base64. Supports PNG, JPG, JPEG, GIF formatsiVBORw0KGgoAAAANS...
addImageHeaderFooterToExcelAction*ObjectAction configuration (position, worksheet targeting, margins, etc.)See Payload example below

Optional Parameters (inside addImageHeaderFooterToExcelAction)

ParameterTypeDescriptionExample
isHeaderBooleanPlacement selection. true = Add image to document header (default), false = Add image to document footertrue
positionStringHorizontal alignment within header/footer. Left, Center, or Right. Default: "Center". Case-insensitiveCenter
worksheetNamesArray (string[])Array of worksheet names to apply image to. If both worksheetNames and worksheetIndexes are empty, applies to all worksheets["Sheet1", "Report"]
worksheetIndexesArray (int[])Array of worksheet indexes (1-based). If both worksheetNames and worksheetIndexes are empty, applies to all worksheets[1, 2]
topMarginNumber (double)Top page margin in centimeters. Default: 1.91.9
bottomMarginNumber (double)Bottom page margin in centimeters. Default: 1.91.9
leftMarginNumber (double)Left page margin in centimeters. Default: 1.91.9
rightMarginNumber (double)Right page margin in centimeters. Default: 1.91.9
cultureNameStringCulture code for document processing (e.g., "en-US", "de-DE", "fr-FR")en-US

Note: If both worksheetNames and worksheetIndexes are empty or null, the image will be applied to all worksheets in the Excel file.

Output

The PDF4me Add Image Header Footer REST API returns the Excel 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": "data.xlsx",
"success": true,
"errorMessage": null
}

Response Fields:

  • document (string): The Excel document with image header/footer applied, encoded as Base64 string
  • fileName (string): The output Excel 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 Excel document data
  3. Save or process the Excel file as needed

Example (JavaScript):

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

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 (Required Fields Only):

{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"imageContent": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"addImageHeaderFooterToExcelAction": {}
}

Advanced Example (With All Optional Fields):

{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"imageContent": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"addImageHeaderFooterToExcelAction": {
"isHeader": true,
"position": "Center",
"worksheetNames": ["Sheet1", "Report"],
"worksheetIndexes": [1, 2],
"topMargin": 1.9,
"bottomMargin": 1.9,
"leftMargin": 1.9,
"rightMargin": 1.9,
"cultureName": "en-US"
}
}

Code Samples

The PDF4me Add Image Header Footer to Excel 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 adding image headers/footers to Excel documents:

Industry Use Cases & Applications

Finance & Accounting Use Cases

  • Financial Statements: Add company logo headers to quarterly reports
  • Budget Reports: Insert department logos on budget worksheets
  • Audit Documents: Apply audit firm logo watermarks in footers
  • Expense Reports: Add corporate logo headers for expense submissions

Get Help