Aspose html to pdf with header footer

Hi Team,

We are evaluating your product to replace one of our existing api for converting html to PDF/Word.

However, While going thru your api I could not find an option to provide header footer for conversion. I want my header and footer to repeat on every page so I cant pass it in html.
Is there a way?

Can you please guide .

And We also have the requirement to convert html to word and there as well we need to pass in header and footer.

Please suggest if you have option to pass header and footer (“Text” and “html”) while converting html to pdf/word?

And I am also listing all the features we may need , Please reply what all do you have?

  • HTML to PDF conversion**
  • HTML to WORD conversion**
  • Support for merging files**
  • Support for header footers**
  • Support for various fonts and font sizes**
  • Support for generating Table of contents**
  • Support for embedding images/Files**
  • Support for Converting large files ( i.e 100-200 pages)**

Abhishek

@abhisheknagarro

Thank you for contacting us.

HTML to PDF conversion**

Please check HTML to PDF Conversion article regarding how to convert HTML document to PDF. The article contains cURL examples as well as SDK Examples. You may use Aspose.HTML Cloud SDKs to quickly integrate Aspose.HTML APIs into your project.

HTML to WORD conversion**

Unfortunately, there is no API to directly convert HTML document to Word. But you can convert PDF document to Word with the following API:

POST /words/{name}/saveAs

Please check Convert PDF Document to Word article for documentation of this API. Aspose.Words Cloud SDKs are available at following GitHub account: Aspose.Words Cloud · GitHub

However, While going thru your api I could not find an option to provide header footer for conversion. I want my header and footer to repeat on every page so I cant pass it in html.
Is there a way?

With Aspose.Words Cloud APIs you can add Header and Footer to a new or existing Word document. Following are the steps to add Header and Footer:

1- Add header with PUT method (it will create one empty paragraph). You may test the API live in the browser by setting following values of the parameters:
name = SampleDocument.docx
headerFooterType = “HeaderFirst” (Note the Double quotes)
destFileName = SampleDocument_Result.docx

The API should return the following response:

{
  "HeaderFooter": {
    "Paragraphs": {
      "link": {
        "Href": "http://api.aspose.cloud/v1.1/words/SampleDocument_Result.docx/sections/0/headersfooters/0/paragraphs",
        "Rel": "self",
        "Type": null,
        "Title": null
      }
    },
    "DrawingObjects": {
      "link": {
        "Href": "http://api.aspose.cloud/v1.1/words/SampleDocument_Result.docx/sections/0/headersfooters/0/drawingObjects",
        "Rel": "self",
        "Type": null,
        "Title": null
      }
    },
    "Type": "HeaderFirst",
    "link": {
      "Href": "http://api.aspose.cloud/v1.1/words/SampleDocument_Result.docx/sections/0/headersfooters/0",
      "Rel": "self",
      "Type": null,
      "Title": null
    }
  },
  "Code": 200,
  "Status": "OK"
}

The possible values of headerFooterType parameter values are:

  1. HeaderEven
  2. HeaderPrimary
  3. FooterEven
  4. FooterPrimary
  5. HeaderFirst
  6. FooterFirst

2- Please use the following API to add text to paragraph (or add another paragraph or image or anything that you want):

PUT /words/{name}/{paragraphPath}/runs
The parameter values would be:

name = SampleDocument_Result.docx
paragraphPath = sections/0/headersfooters/0/paragraphs/0
run = { “Text”: “hello!” }

The API response should be as follows:

{
  "Run": {
    "Text": "hello!",
    "NodeId": "0.0.0.0",
    "link": {
      "Href": "http://api.aspose.cloud/v1.1/words/SampleDocument_Result.docx/sections/0/headersfooters/0/paragraphs/0/runs/0",
      "Rel": "self",
      "Type": null,
      "Title": null
    }
  },
  "Code": 200,
  "Status": "OK"
}

Now finally set DifferentFirstPageHeaderFooter value to true using following API:
POST /words/{name}/sections/{sectionIndex}/pageSetup. The parameter values would be:

name = SampleDocument_Result.docx
sectionIndex = 0
pageSetup = { “DifferentFirstPageHeaderFooter”: true }

The API response should be as follows:

{
  "PageSetup": {
    "Bidi": false,
    "BorderAlwaysInFront": true,
    "BorderAppliesTo": "AllPages",
    "BorderDistanceFrom": "Text",
    "BottomMargin": 36,
    "DifferentFirstPageHeaderFooter": true,
    "FirstPageTray": 0,
    "FooterDistance": 35.4,
    "Gutter": 0,
    "HeaderDistance": 35.4,
    "LeftMargin": 36,
    "LineNumberCountBy": 0,
    "LineNumberDistanceFromText": 0,
    "LineNumberRestartMode": "RestartPage",
    "LineStartingNumber": 1,
    "Orientation": "Portrait",
    "OtherPagesTray": 0,
    "PageHeight": 841.95,
    "PageNumberStyle": "Arabic",
    "PageStartingNumber": 1,
    "PageWidth": 595.35,
    "PaperSize": "A4",
    "RestartPageNumbering": false,
    "RightMargin": 36,
    "RtlGutter": false,
    "SectionStart": "NewPage",
    "SuppressEndnotes": false,
    "TopMargin": 36,
    "VerticalAlignment": "Top",
    "link": {
      "Href": "http://api.aspose.cloud/v1.1/words/SampleDocument_Result.docx/sections/0/pagesetup",
      "Rel": "self",
      "Type": null,
      "Title": null
    }
  },
  "Code": 200,
  "Status": "OK"
}

Input Document: SampleDocument.docx.zip (49.8 KB)
Output Document: SampleDocument_Result.docx.zip (97.4 KB)

Support for merging files**

Please use following API to merge PDF documents:
PUT /pdf/{name}/merge

Support for Converting large files ( i.e 100-200 pages)**

With Aspose APIs you can convert documents of any size.

We hope this helps.

Thanks for the reply.

As the option to add header footer is explained for word. Do we have similar option in PDF.

Hi Team,

As per your suggestion, we did a Pdf → Word conversion. Please find attached the pdf and word files attached.
The word is not coming correctly.

test.pdf (75.8 KB)
Report_With_Issue.zip (4.0 KB)

Details of the call:-

  1. Api: https://api.aspose.cloud:443/v1.1/words/test.pdf/saveAs?folder=pdf&destFileName=Report_with_issue.docx&appsid=d0be9009-0eb0-4b28-813f-f0940c6a789b&signature=VdJQkf3fwHBoJs1f727SybXoa6o
  2. name: test.pdf
  3. saveOptionsData: {

“SaveFormat”: “doc”,
“FileName”: “Report_With_Issue.doc”,
“ZipOutput”: false,
“UpdateLastSavedTimeProperty”: true,
“UpdateSdtContent”: true,
“UpdateFields”: true
}
4. folder: pdf
5. destFileName: Report_with_issue.doc

@nipunjainindia

We are able to reproduce the issue (WORDSCLOUD-545) on our end and working to fix it at the earliest opportunity. We will update you here as soon as the issue is fixed.

Hi Team,

Thanks for your prompt responses.

Attaching a set of input files and an output file that would describe our requirement a bit better.
Input Files are present in Input Files.zip (45.5 KB) :-

  1. cover_page.html: First page in the final pdf / word.
  2. table_of_contents.html: Second page in the final pdf / word.
  3. report_with_issue.html: The actual report succeding the cover page and toc pages.
  4. header.html: The header that needs to be applied to all the pages corresponding to pages in report_with_issue.html.
  5. footer.html: The footer that needs to be applied to all the pages corresponding to pages in report_with_issue.html.

We are providing below mentioned margins:-

  1. Top, Bottom: 15px
  2. Left, Right: 25px

The output file after merging all the input files is final_report.pdf (104.7 KB)

Regards,
Nipun Jain

Hi,

Thanks for replying back and working for a solution for us.

Can you please also reply for one of the question above :

“Is there a possibility to pass in header and footer through the coud api while converting html to pdf”?

Thanks

@abhisheknagarro

“Is there a possibility to pass in header and footer through the coud api while converting html to pdf”?

You cannot do this in one API call. But with following four steps you can convert HTML document to PDF and add Header and Footer to the PDF document:

  1. First, convert HTML to PDF Aspose.HTML Cloud - API References
  2. Convert PDF to Word Aspose.Pdf Cloud - API References
  3. Add Header and Footer to Word Document (As explained above)
  4. Convert Word Document to PDF Aspose.Words Cloud - API References

Please let us know if you require any further information.

@nipunjainindia

As per your suggestion, we did a Pdf -> Word conversion. Please find attached the pdf and word files attached.
The word is not coming correctly.

Please use following Aspose.PDF API to convert PDF document to Word:
https://apireference.aspose.cloud/pdf/#!/Convert/PutPdfInStorageToDoc

Input Document: test.pdf (75.8 KB)
Output document: test.docx (166.1 KB)

The following Aspose.Words API is causing an issue while converting PDF document to Word, we are working to fix it:

Hi Team,

We are getting this message “Sorry, this file is private. Only visible to topic owner and staff members.” while trying to download files attached from your side.

Some of those files are:-

  1. SampleDocument.docx.zip
  2. SampleDocument_Result.docx.zip
  3. test.docx

Can you please make them public.

Regards,
Nipun Jain

@nipunjainindia

Would you please confirm are you logged into https://forum.aspose.cloud/ website while downloading these files.

Hi Team,

we followed the process to add header/footer to a word file .And we could successfully do that with “Text”.

How can we add html to header and footer with custom css?
We would also need to add image/logo to header and footer . will that be possible.

can you please share a working example.

Thanks

@abhisheknagarro

We would also need to add image/logo to header and footer . will that be possible.

Yes, you can add Image/Logo to Header and Footer. I will shortly share an example with you.

@abhisheknagarro

Please use following API to add Image/Logo to Header and Footer of a Word Document:
PUT /words/{name}/{nodePath}/drawingObjects

The parameter values could be as follows:
name = SampleDocument_Result.docx
drawingObject = { “Left”: 0 }
imageFile = environment.png
destFileName = SampleDocument_Drawing.docx
nodePath = sections/0/headersfooters/0/paragraphs/0

Input Document: SampleDocument_Result.docx (97.4 KB)
Image File: environment.png (3.3 KB)
Output Document: SampleDocument_Drawing.docx (108.9 KB)

drawingObject object can contain the following parameters:

  1. Parameter Name: Left
    Type: double
    Description: Distance in points from the origin to the left side of the image.

  2. Parameter Name: Top
    Type: double
    Description: Distance in points from the origin to the top side of the image.

  3. Parameter Name: Width
    Type: double
    Description: Width of the drawing objects in points.

  4. Parameter Name: Height
    Type: double
    Description: Height of the drawing object in points.

  5. Parameter Name: WrapType
    Type: string
    Description: Specifies how to wrap text around the image. It values could be None, Inline, TopBottom, Square, Tight or Through

  6. Parameter Name: RelativeVerticalPosition
    Type: string
    Description: Specifies where the distance to the image is measured from. It values could be Margin, Page, Paragraph, Line, TopMargin, BottomMargin, InsideMargin, OutsideMargin, TableDefault or TextFrameDefault

  7. Parameter Name: RelativeHorizontalPosition
    Type: string
    Description: Specifies where the distance to the image is measured from. It values could be Margin, Page, Column, Character, LeftMargin, RightMargin, InsideMargin, OutsideMargin, Default

  8. Parameter Name: Position
    Type: DocumentPosition
    Description: Drawing object will be inserted before a specified position.

We hope this helps!

Hi Sohail,

Thanks a lot for the response we are checking it now. Meanwhile can you answer the other question in the same thread ?

How can we add html to header and footer with custom css?

Abhishek

@abhisheknagarro

How can we add html to header and footer with custom css?

At present, you cannot add HTML to Header and Footer with custom CSS. But with the following API you can update all possible Font properties of text:
POST /words/{name}/{paragraphPath}/runs/{index}/font

Moreover, with the following API you can get the current values of these Font properties:
GET /words/{name}/{paragraphPath}/runs/{index}/font

Hi Team,

Can you please look into this, as this would answer all our questions.

Regards,
Nipun Jain

Hi Team,

Thanks for responding so far on all of our queries. We would appreciate if you guys can reply to the below and help us in coming to a conclusion :

Today We tried the following route as recommended by you:-
Html → Pdf → Word → Word + Header Text → Word + Header Text + Logo + Update font for word

And We used the following apis to achieve the above:
Html → Pdf
https://apireference.aspose.cloud/pdf/#!/Convert/PutHtmlInStorageToPdf

Pdf → Word
https://apireference.aspose.cloud/pdf/#!/Convert/PutPdfInStorageToDoc

Word → Word + Header Text

Word + Header Text → Word + Header Text + Logo + Update font for word

We faced some more issues which are listed below :

Html → Pdf

  • Not able to properly set the page size (A4)
  • In case of two inline elements (e.g. Table), The position and content are not top aligned.
  • Unwanted page breaks/New Pages are introduced

Pdf → Word

  • Same as above as the conversion is happening from pdf to word

Word → Word + Header Text

  • Not able to set the position/alignment of the text

Word + Header Text → Word + Header Text + Logo + Update font for word

  • Not able to set the size/position/alignment of the image
  • Not able to set any font related property on the text (e.g. font size, color etc)

For you guys to understand the problems we are attaching all the relevant files with corresponding naming convention.

It would be really helpful for both of us if you can reply at the earliest for this. Maybe with a complete flow of apis with specific parameters.

Our goal is to convert one html to PDF/Word with header/footer having logos. And also customization font for the header and footer text. (e.g. font size, font-family, bold, italic , text-alignment etc)
Aspose_File_Set.zip (389.1 KB)

Hi Team,

Do we have any future plans to add this functionality “html to word” directly.

@abhisheknagarro

We have logged the request in our internal tracking software as HTMLCLOUD-629 for the implementation of direct HTML to Word conversion. After the initial investigation, we will share with you an approximate implementation date.