Apply Headers and Footers on DOCX API - ApyHub

Apply Headers and Footers on DOCX API

ApyHub
ApyHub
verified icon
100 atoms
Base tier

About

This API lets you add headers, footers with page numbers and table of contents to your existing DOCX files.
You can provide text or PNG images as headers and footers, control font size and opacity, and add table of contents to your DOCX files.
This API automates the process of adding professional headers, footers, and table of contents to multiple DOCX files, saving time while maintaining consistent branding and document standards.
⚠️ Important:
If you use this API to add a table of contents, you must open the resulting DOCX file in Microsoft Word and right-click at the end of the line "Right Click here to update Table of Contents:", and select "Update Field" to refresh and display the table of contents.
Table of content will dynamically update based on the headings in the document(Heading 1 and Heading 2).
Try out the API in the API playground and see how this API can help you save time, and add context and branding elements to documents for free through a simple API call.
Currently we support more than 50 languages for text in this utility.
Supported Languages: Esperanto, English, Russian, Mandarin, Spanish, Portuguese, Italian, Bengali, French, German, Ukrainian, Georgian, Arabic, Hindi, Japanese, Hebrew, Yiddish, Polish, Javanese, Korean, Bokmal, Danish, Swedish, Finnish, Turkish, Dutch, Hungarian, Czech, Greek, Bulgarian, Belarusian, Marathi, Kannada, Romanian, Slovene, Croatian, Serbian, Macedonian, Lithuanian, Latvian, Estonian, Tamil, Vietnamese, Urdu, Thai, Gujarati, Uzbek, Punjabi, Azerbaijani, Indonesian, Telugu, Malayalam, Hausa, Oriya, Burmese, Bhojpuri, Maithili, Oromo, Kurdish, Malagasy, Saraiki, Nepali, Sinhalese, Khmer, Turkmen, Somali, Akan, Zulu, Haitian Creole, Africaans
Select API Endpoints
Input
Output

API Playground

API Documentation

input file: output file
POST
https://api.apyhub.com/stamp/docx/footers/file

Request example

1
curl --location --request POST 'https://api.apyhub.com/stamp/docx/footers/file?output=test-sample' \
2
--header 'apy-token: {{token}}' \
3
--form 'file= @"sample.docx"'
4
--form 'header_text="ApyHub Header"'
5
--form 'footer_text="ApyHub Footer"'
6
--form 'include_table_of_content=true'
7
--form 'table_of_content_heading="Table of Contents"'
Method: POST
Content Type: multipart/form-data
Query Parameter(s)
AttributeTypeMandatoryDescription
outputStringNoThe name of the output file, defaults to test-sample.docx.
Request Body
AttributeTypeMandatoryDescription
fileFileYesProvide the source DOCX file.
header_textStringYes (if header_image is not given and include_table_of_content is false)Input text which you want to add as Header. If header_text and header_image both are present in the request then header_text will be applied.
footer_textStringYes (if footer_image is not given and include_table_of_content is false)Input text which you want to add as Footer. If footer_text and footer_image both are present in the request then footer_text will be applied.
header_opacityFloatNoProvide the level of transperancy for header you want to keep from 0 to 1, defaults to 1.
footer_opacityFloatNoProvide the level of transperancy for footer you want to keep from 0 to 1, defaults to 1.
header_font_sizeNumberNoProvide the font size of Header text from 8 to 24, defaults to 12.
footer_font_sizeNumberNoProvide the font size of Footer text from 8 to 24, defaults to 12.
header_alignmentStringNoProvide alignment of the Header - can have the values 'left', 'right', or 'center', with the default being center.
footer_alignmentStringNoProvide alignment of the Footer - can have the values 'left', 'right', or 'center', with the default being center.
header_imageFileYes (if header_text not given and include_table_of_content is false)Provide the png image file which you want to add as Header. If header_text and header_image both are present in the request then header_text will be applied.
footer_imageFileYes (if footer_text not given and include_table_of_content is false)Provide the png image file which you want to add as Footer. If footer_text and footer_image both are present in the request then footer_text will be applied.
header_image_sizeFloatNoProvide size of the image header you want to set from 0.1 to 1, defaults to 0.1.
footer_image_sizeFloatNoProvide size of the image footer you want to set from 0.1 to 1, defaults to 0.1.
include_table_of_contentBooleanYes (if header_text or header_image or footer_text or footer_image is not given)Provide true if you want to add table of contents to your DOCX file, defaults to false.
table_of_content_headingStringNoProvide the heading for the table of contents, defaults to Table of Contents. If include_table_of_content is false or not provided then this parameter will be ignored.
Sample Response
A successful request returns the docx file in the output parameter specified. If the request fails, the response contains an error code and a message to help determine what went wrong.

HTTP Response Codes

The method may return one of the following HTTP status codes:
Status CodeDescription
200The request was successful.
400Invalid input - the docx file is corrupt or the supported inputs are not provided.
401Required authentication information is either missing or not valid for the resource.
500If any unexpected error occurs while processing the request.

Authentication

All API requests to ApyHub services need to be authenticated. Currently we support tokens or basic authentication mechanisms. You can generate and view your existing credentials from your workspace settings (on the left side of the navbar) and go to “API Keys".
Points to note:
  • Credential secrets are generated on the fly and are not stored in plain text, so on generating a credential please save the secrets somewhere safe.
  • Use the apy-token as the header parameter to pass the token.
  • Use the Authorization header to send the basic authentication credentials.

Error codes

1
{
2
"error": {
3
"code": 105,
4
"message": "Invalid URL"
5
}
6
}
To search for a specific error code, enter the code in the search box below. Alternatively, you can click on the button to view a complete list of all error codes.
Table of contents
AboutAPI PlaygroundAPI DocumentationAuthenticationError codesRelated Utility APIsRelated Articles