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)
| Parameter | Type | Description | Example |
|---|---|---|---|
| document* | Object | Document reference. Must contain Name (string) — Excel file name with .xlsx or .xls extension | { "Name": "data.xlsx" } |
| docContent* | String (Base64) | Excel document content encoded in Base64 | UEsDBBQABgAIAAAA... |
| imageContent* | String (Base64) | Image file content encoded in Base64. Supports PNG, JPG, JPEG, GIF formats | iVBORw0KGgoAAAANS... |
| addImageHeaderFooterToExcelAction* | Object | Action configuration (position, worksheet targeting, margins, etc.) | See Payload example below |
Optional Parameters (inside addImageHeaderFooterToExcelAction)
| Parameter | Type | Description | Example |
|---|---|---|---|
| isHeader | Boolean | Placement selection. true = Add image to document header (default), false = Add image to document footer | true |
| position | String | Horizontal alignment within header/footer. Left, Center, or Right. Default: "Center". Case-insensitive | Center |
| worksheetNames | Array (string[]) | Array of worksheet names to apply image to. If both worksheetNames and worksheetIndexes are empty, applies to all worksheets | ["Sheet1", "Report"] |
| worksheetIndexes | Array (int[]) | Array of worksheet indexes (1-based). If both worksheetNames and worksheetIndexes are empty, applies to all worksheets | [1, 2] |
| topMargin | Number (double) | Top page margin in centimeters. Default: 1.9 | 1.9 |
| bottomMargin | Number (double) | Bottom page margin in centimeters. Default: 1.9 | 1.9 |
| leftMargin | Number (double) | Left page margin in centimeters. Default: 1.9 | 1.9 |
| rightMargin | Number (double) | Right page margin in centimeters. Default: 1.9 | 1.9 |
| cultureName | String | Culture 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.
- 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": "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:
- Extract the
documentfield from the JSON response (Base64) - Decode the Base64 string to get the binary Excel document data
- 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
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,imageContent,addImageHeaderFooterToExcelAction) - Invalid Base64 encoding in
docContentorimageContent - Invalid or corrupted Excel document
- Invalid or corrupted image file
- Invalid worksheet selection (names or indexes don't exist or are out of range)
- Invalid or missing API key
- API key not properly Base64 encoded in Authorization header
- Missing
Authorization: Basicheader
- Server-side processing error
- Excel document processing failure
- Image header/footer addition failure
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON, never binary Excel data directly.
Response Structure:
{
"document": "string", // Base64-encoded Excel document content
"fileName": "string", // Output Excel filename
"success": true,
"errorMessage": "string or null"
}
Decoding Base64 to Excel 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
excel_bytes = base64.b64decode(response['document'])
with open('output.xlsx', 'wb') as f:
f.write(excel_bytes)
C#:
byte[] excelBytes = Convert.FromBase64String(response.document);
File.WriteAllBytes("output.xlsx", excelBytes);
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 (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#
- Java
- JavaScript
- Python
C# (CSharp) Sample
Complete C# implementation for adding image headers/footers to Excel documents:
Industry Use Cases & Applications
- Finance & Accounting
- Sales & Marketing
- Human Resources
- Operations & Manufacturing
- Healthcare & Medical
- Legal & Professional Services
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
Sales & Marketing Use Cases
- Sales Reports: Insert company branding logos on weekly sales reports
- Pricing Sheets: Add logo headers to customer pricing documents
- Marketing Reports: Apply campaign logos to analytics reports
- Customer Presentations: Add client co-branding logos to deliverables
Human Resources Use Cases
- Payroll Reports: Insert company logo headers on salary documents
- Employee Records: Add HR department logo to personnel templates
- Benefits Enrollment: Apply benefits provider logos to enrollment sheets
- Performance Reviews: Add corporate branding to review templates
Operations & Manufacturing Use Cases
- Inventory Reports: Insert warehouse location logos on inventory sheets
- Production Reports: Add production facility logos to manufacturing reports
- Quality Reports: Apply quality certification logos in headers
- Supply Chain Reports: Add vendor logos to procurement documents
Healthcare & Medical Use Cases
- Patient Reports: Add hospital or clinic logo headers to patient data
- Lab Results: Insert laboratory logo branding on test result sheets
- Insurance Claims: Apply insurance provider logos to claims documents
- Medical Records: Add facility branding to health information sheets
Legal & Professional Services Use Cases
- Client Reports: Insert law firm logo headers on client deliverables
- Case Documents: Add practice area logos to legal case files
- Contract Templates: Apply firm branding to contract worksheets
- Billing Statements: Insert company logo on legal billing reports