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.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog →

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: REST 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.

ParameterRequiredWhat it doesExample
jobIdExtOptionalYour own reference for this call. It is stored with the API call log so you can correlate calls with your jobs. Type: string.
integrationsOptionalIntegration identifiers, forwarded unchanged with the job's notification settings. Type: array.
isAsyncOptionalSet to `true` to process the action asynchronously and get a job to poll at `/api/v2/GetActionStatus`. Only honoured by actions that support asynchronous processing. Type: boolean.true
docNameOptionalSource file name including its extension. Several actions dispatch on the extension, so it should always be set; when omitted a per-action default is used. Type: string.output.pdf
docContentRequiredThe source file. Accepts the base64-encoded file content, a `pdf4meblobid://<id>` reference to a previously uploaded blob, or an `https` URL to the source document. Required: an empty value fails with `File is empty`. Type: string.JVBERi...
docContentBytesOptionalAlternative raw byte payload for the source file. Type: string.
callBackUrlOptionalOptional URL notified when an asynchronous job completes. Type: string.
HTMLContentOptionalRequired. HTML markup (plain text, not base64) to render as the header or footer. Type: string.<div style="text-align: center; font-family: Arial; font-size: 12px; color: #FF0000;">Document Header PDF4me</div>
locationOptionalAn unrecognised value is rejected with 400. Type: string.Header
skipFirstPageOptionalDo not add the header or footer to the first page. Type: boolean.false
marginLeftOptionalLeft margin of the header or footer area. Type: number.20.0
marginRightOptionalRight margin of the header or footer area. Type: number.20.0
marginBottomOptionalBottom margin of the header or footer area. Type: number.50.0
marginTopOptionalTop margin of the header or footer area. Type: number.50.0
pagesOptionalPages to add the header or footer to, e.g. `1`, `1,3,5`, `2-5` or `2-` (2 to the last page). Type: string.""` or `"1-3"

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​