Footer in PDF

The footer is placed at the bottom or foot of PDF pages. Typically it’s used for inserting document information, such as the name of the document, page numbers, creation date, etc. When specifically talking about documents or letters, the footers often include the date, editing date, page numbers, logo, company name, contact information, links, and author name. These are printed on designated pages of the document at the bottom and can be adjusted to position on the left, center, or right side. Another term used for the footer is called “running foot.” This term is greatly used in the publishing industry and is called as such because it contains a shortened version of the article or other pieces of information about it. In this article, we are going to discuss the steps on how to add Text and Image footer in PDF using Python as well as cURL commands.

Free Cloud SDK

Aspose.PDF Cloud SDK for Python enables us to implement PDF processing capabilities in Python applications. In order to get started, the first step in usage is its installation and it’s available for free download over PIP and GitHub repository. Simply execute the following command on the terminal/command prompt to install the latest version of SDK on the system.

pip install asposepdfcloud

Cloud Dashboard Account

Aspose Cloud dashboard enables our customers to manage their credentials as well as the files stored in their specific storage. So in order to use Cloud APIs, the next major step is a free subscription to our cloud services via Aspose.Cloud dashboard. The purpose of this subscription is to only allow authorized persons to access our file processing services. If you have GitHub or Google account, simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client credentials

Image 1:- Client Credentials on Aspose.Cloud Dashboard.

Please follow the steps given below to add text footer in PDF document using Python code snippet.

  • The first step is to create an instance of ApiClient class which requires Client ID Client Secret as arguments
  • Secondly, create an instance of PdfApi class which requires ApiClient object as input argument
  • Thirdly, create an object of TextFooter where we have set the horizontal alignment as Center, Opacity as 0.7, rotate angle as 356 and have specified bottom margin as 5.
  • In order to set text formating for TextFooter, create an object of TextState where we define foreground color, font size, font name etc
  • Now we need to set values for two optional parameters defining start and end page of PDF document to place Text Footer
  • Finally, call the post_document_text_footer(..) method to add Text Footer to PDF document and save resultant file to Cloud storage
Text Footer preview

Image 2:- Preview of TextFooter added to PDF.

Please visit the following link to download the input marketing.pdf and resultant marketing-TextFooter.pdf.

The API also provides the capabilities to add an Image footer to a PDF file. Please follow the instructions given below to accomplish this requirement.

  • The first step is to create an instance of ApiClient class which requires Client ID Client Secret as arguments
  • Secondly, create an instance of PdfApi class which requires ApiClient object as input argument
  • Thirdly, create an object of ImageFooter where we have set the horizontal alignment as Center, Opacity as 0.7, rotate angle as 10, image file name, margin details and other properties are specified
  • Since we only need to add the Footer to first page of document, so we have set values for start_page_number and end_page_number optional parameters
  • Finally, call the post_document_image_footer(..) method to add Text Footer to PDF document and save resultant file to Cloud storage
Image Footer in PDF

Image 3:- Preview of Image Footer in PDF.

The resultant file generated by the above example can be downloaded from marketing-ImageFooter.pdf.

The REST APIS can also be accessed via the cURL commands on any platform using the command line terminal. Similarly, Aspose.PDF Cloud can also be accessed via cURL commands to add Text and Image headers in PDF documents. However, we have a pre-requisite to generate a JSON Web Token (JWT) based on your client credential details specified over Aspose.Cloud dashboard. This step is mandatory because our APIs are only accessible to registered users. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=88d1cda8-b12c-4a80-b1ad-c85ac483c5c5&client_secret=406b404b2df649611e508bbcfcd2a77f" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now that we have generated the JWT token, we need to execute the following command to add TextFooter to PDF file.

curl -X POST "https://api.aspose.cloud/v3.0/pdf/marketing.pdf/footer/text?startPageNumber=2&endPageNumber=3" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"Background\": true,  \"HorizontalAlignment\": \"Center\",  \"Opacity\": 0.7,  \"Rotate\": \"None\",  \"RotateAngle\": 5,  \"XIndent\": 100,  \"YIndent\": 100,  \"Zoom\": 0.8,  \"Value\": \"Aspose.PDF Cloud SDK for Python\",  \"TextState\": {    \"FontSize\": 15,    \"Font\": \"Arial\",    \"ForegroundColor\": {      \"A\": 0,      \"R\": 66,      \"G\": 111,      \"B\": 245    },    \"BackgroundColor\": {      \"A\": 10,      \"R\": 179,      \"G\": 245,      \"B\": 66    },    \"FontStyle\": \"Regular\"  },  \"BottomMargin\": 3,  \"LeftMargin\": 3,  \"RightMargin\": 3}"

Please execute the following command to add the image header to the PDF file using the cURL command.

curl -X POST "https://api.aspose.cloud/v3.0/pdf/marketing.pdf/footer/image?startPageNumber=1&endPageNumber=1" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"Background\": false,  \"HorizontalAlignment\": \"Left\",  \"Opacity\": 0.7,  \"Rotate\": \"None\",  \"RotateAngle\": 10,  \"XIndent\": 10,  \"YIndent\": 10,  \"Zoom\": 0.7,  \"FileName\": \"Koala.jpg\",  \"Width\": 100,  \"Height\": 100,  \"BottomMargin\": 2,  \"LeftMargin\": 1,  \"RightMargin\": 10}"

Conclusion

Let’s recap our learning in this article. We have discussed the capabilities of Aspose.PDF Cloud SDK for Python for adding Text and Image Headers in PDF files. Similarly, we have also learned about the flexibility of using API through cURL commands. Furthermore, please note that our Cloud SDKs are developed under MIT license, so their complete code snippet is available for free download over GitHub. Should you have any related queries or you encounter any issues while using our APIs, please feel free to contact us via the free customer support forum.

We recommend visiting the following articles to learn about: