Skip to main content

Add HTML Header Footer to PDF - Branding API

PDF4me Add HTML Header Footer to PDF enables you to add HTML content as headers, footers, or both to PDF documents. This API service processes PDF files and adds HTML content with precise positioning, custom margins, and page targeting options for document branding and organization. The API receives PDF content and HTML data through REST API calls, utilizing Base64 encoding for secure PDF transmission. With support for HTML content, flexible positioning, custom margins, page targeting, and first page exclusion, this solution is ideal for document branding, report generation, and enterprise PDF 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

  • HTML Content Support: Add rich HTML content as headers and footers with full styling support
  • Flexible Positioning: Control header and footer placement with precise margin control
  • Custom Styling: Full HTML and CSS support for professional appearance
  • Page Targeting: Apply headers and footers to specific pages or entire documents
  • Skip First Page: Option to exclude headers and footers from the first page
  • Professional Results: Create headers and footers that enhance document organization and branding
  • Seamless API Integration: RESTful API designed for automated PDF editing workflows and enterprise system integration

REST API Endpoint

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

  • Method: POST
  • Endpoint: /api/v2/AddHtmlHeaderFooter

HTML Content Support

  • HTML Content: Support for HTML content with inline CSS styling
  • Custom Styling: Use inline CSS for fonts, colors, alignment, and basic styling
  • Text and Images: Support for HTML text content and embedded images
  • Plain HTML String: HTML content must be provided as a plain string (not Base64 encoded)

Positioning and Layout

  • Margin Control: Precise positioning with pixel-based measurements (marginLeft, marginRight, marginTop, marginBottom)
  • Page Targeting: Apply to specific pages using page options (empty string for all pages, "1", "1,3,5", "2-5", "1,3,7-10", "2-")
  • Skip First Page: Option to exclude headers and footers from the first page
  • Location Options: Add content as Header, Footer, or Both

Advanced Features

  • Asynchronous Processing: Support for async processing with polling for long-running operations
  • Professional Appearance: Consistent formatting and styling across documents
  • Flexible Positioning: Control header and footer placement with exact pixel measurements

REST API Parameters

Complete list of parameters for the Add HTML Header Footer to PDF REST API. Parameters are organized by category for better understanding and implementation.

Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.

Required Parameters

ParameterTypeDescriptionExample
docName*StringOutput PDF file name with .pdf extensionoutput.pdf
docContent*Base64The content of the input PDF file encoded in Base64JVBERi...
htmlContent*StringHTML content (plain HTML string, NOT base64 encoded) to be added as header or footer<div style="text-align: center; font-family: Arial; font-size: 12px; color: #FF0000;">Document Header PDF4me</div>
location*StringLocation for HTML content: Header, Footer, or BothHeader

Optional Parameters

ParameterTypeDescriptionExample
pagesStringPage options: empty string for all pages, "1" for page 1, "1,3,5" for specific pages, "2-5" for page range, "1,3,7-10" for mixed, "2-" for pages from 2 to end"" or "1-3"
skipFirstPageBooleanSkip first page (true) or include first page (false)false
marginLeftDoubleLeft margin in pixels20.0
marginRightDoubleRight margin in pixels20.0
marginTopDoubleTop margin in pixels50.0
marginBottomDoubleBottom margin in pixels50.0
asyncBooleanEnable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location headertrue

Important Note: The htmlContent parameter must be a plain HTML string, not Base64 encoded. You can include inline CSS styling within the HTML.

Output

The PDF4me Add HTML Header Footer to PDF REST API returns different responses based on the processing mode. The API returns the PDF as a Base64-encoded string in JSON format, not as binary data.

Synchronous Processing (Default)

When async is not set or set to false, the API processes the request immediately:

Status Code: 200 OK

Content-Type: application/json

Response Body:

{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg=="
}

Response Fields:

  • docName (string): The output PDF file name
  • docContent (string): The PDF file with HTML header/footer applied, encoded as Base64 string

How to Use:

  1. Extract the docContent field from the JSON response
  2. Decode the Base64 string to get the binary PDF data
  3. Save or process the PDF file as needed

Example (JavaScript):

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

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):

{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"htmlContent": "<div style='text-align: center; font-family: Arial; font-size: 12px; color: #FF0000;'>Document Header PDF4me</div>",
"location": "Header"
}

Advanced Example (With All Optional Fields):

{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"htmlContent": "<div style='text-align: center; font-family: Arial; font-size: 12px; color: #FF0000;'>Document Header PDF4me</div>",
"location": "Header",
"pages": "",
"skipFirstPage": false,
"marginLeft": 20.0,
"marginRight": 20.0,
"marginTop": 50.0,
"marginBottom": 50.0,
"async": true
}

Important: The htmlContent field must contain plain HTML as a string, not Base64 encoded. You can use inline CSS styling within the HTML tags.

Code Samples

The PDF4me Add HTML Header Footer to PDF 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 headers and footers to PDF:

Industry Use Cases & Applications

Legal & Professional Services Use Cases

  • Legal Documentation: Apply legal disclaimers and confidentiality notices to legal documents
  • Contract Headers: Add headers and footers to contracts and agreements
  • Compliance Documentation: Include compliance notices in headers and footers
  • Client Documentation: Add professional headers and footers to client documents

Get Help