Add Header/Footer in HTML to PDF Conversion with Aspose.Words REST API

Hello,


I am using Aspose.Words for Cloud as a REST API to convert an HTML file into a PDF.
How can I set a header and a footer in my html file in order to have “Hello world” on the top left of each page and the page number on the bottom right of each page in the PDF?

Thanks for your help

Dear PrayDesai,

Thank You for contacting Aspose Support.

Aspose.Words for Cloud allows you to modify and manipulate Word documents and convert them to a format of your choice.

Aspose.Words for Cloud supports adding and manipulating Headers in word documents. Unfortunately, due to a bug in our current code base this feature is not working. We have logged a issue WORDSCLOUD-181 in our internal bug tracking System. We will notify you once this features is available.

To add Page Numbers to a Word Document you can use the following cURL command

curl -v “[http://api.aspose.cloud/v1.1/words/{FILENAME}/insertPageNumbers?appSid={APP_ID}&signature={SIGNATURE} ](http://api.aspose.cloud/v1.1/words/%7BFILENAME%7D/insertPageNumbers?appSid=%7BAPP_ID%7D&signature=%7BSIGNATURE%7D)” -d ‘{“Format”: “{PAGE} of {NUMPAGES}”, “Alignment”: “right”, “IsTop”: false, “SetPageNumberOnFirstPage”: true }’ -X POST -H “Content-Type: application/json” -H "Accept: application/json"

You can save a Word document to any format of your choice by using the following cURL command

curl -v “[http://api.aspose.cloud/v1.1/words/{filename}/SaveAs?appSid={APP_ID}&signature={SIGNATURE} ](http://api.aspose.cloud/v1.1/words/%7Bfilename%7D/SaveAs?appSid=%7BAPP_ID%7D&signature=%7BSIGNATURE%7D)” -X POST -d ‘{“SaveFormat”: “pdf”, “FileName”: “Sample.pdf”}’ -H “Content-Type: application/json” -H "Accept: application/json"

You can visit the following document links to learn more of our API

Best Regards

Mateen Sajjad
Aspose – File Format APIs

Got a Complaint? File it!

Keep in touch! We’re on Twitter and Facebook

Hi Mateen,


Thanks for your reply.

But in my case, I’m not using any word file. I’m only using the REST API to convert an HTML file into a pdf.
I have tried to use the html tag and I have tried to use CSS (css - Print page numbers on pages when printing html - Stack Overflow) but nothing worked.
Is there any other way?

Thank you

Hi,

Thank you for your inquiry and sharing details.

Aspose.Words for Cloud API can not help to create PDF from HTML. However we have an API named Aspose.Pdf for Cloud which supports the PDF file creation and manipulation.

To create PDF from HTML please visit link Create PDF from HTML . This article has cURL as well as SDK examples to create PDF from HTML.

You can also use our swagger link to create PDF from HTML and test the API functionality. Please follow below steps to create PDF from HTML and test the API functionality

1- Open URL

https://apireference.aspose.cloud/pdf/#/Convert/PutHtmlInStorageToPdf

2- Enter your App Key and App Sid in right top corner.

3- Enter required parameters name (Generated PDF file name), templateFile (HTML file name, make sure template file is already present on cloud storage), templateType (html) and version (1.1).

4- Click Try it
out button

5- It will
create PDF from HTML on cloud storage and will return you Request URL with
correct signature at the end

If you have any further questions, please feel free to share.

Thanks,
Naeem Akram
Aspose - File Format APIs.

Got a Complaint? File it!

Keep in touch! We’re on Twitter and Facebook

Hello Naeem,


Thanks for your reply.

Aspose.Words for Cloud API can actually convert HTML file to PDF. It is advertised on your website and I have already been using this method in several projects. It is working perfectly but this time I need to add a header and a footer on each page of the PDF…

I have not been able to access your link “Create PDF from HTML”, it requires specific credentials.

I am ok to switch to Aspose.Pdf for Cloud API but can you please provide an HTML template, as an example, which allows to create header and footer on the PDF?

Thank you

Hi,

Thank you for your inquiry and sharing further details.

I have created sample HTML file which have header and footer. You can download or clone examples project using this link GitHub .

Create PDF from HTML example link is also working please visit link Create PDF from HTML .

If you have any further questions, please feel free to share.

Thanks,

Naeem Akram
Aspose - File Format APIs.

Got a Complaint? File it!

Keep in touch! We’re on Twitter and Facebook