Aspose html to pdf with header footer

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.

@nipunjainindia

You used the wrong API for HTML to PDF conversion. You should use the following API to convert HTML to PDF:

PUT /html/convert/pdf.

With the above API, PDF document looks as follows: Sample_Html.pdf.

There is still an alignment issue, apparently, it is because font-family used in PDF document is different from font-family in HTML document. In order to fix this issue, we may need to upload the missing font to our Production server. We are investigating this issue HTMLCLOUD-630 in detail and will share our findings soon.

@nipunjainindia

Following is an API example to update Font, Color, Size and Case of text in Header/Footer of a Word document:

POST /words/{name}/{paragraphPath}/runs/{index}/font

name = MyDocument_R.docx
fontDto = {
“AllCaps”: true,
“Bold”: true,
“Color”: { “Web”: “#1000ff” },
“Name”: “Verdana”,
“Size”: 14
}
paragraphPath = sections/0/headersfooters/0/paragraphs/0
index = 0
destFileName = MyDocument_F.docx

Input Document: MyDocument_R.docx
Output Document: MyDocument_F.docx

@nipunjainindia

Not able to set the size/position/alignment of the image

With attributes Width and Height of drawingObject you can set the size of an Image. By setting Width and Height value to 50, you can reduce the image size by half as shown in the following example:

PUT /words/{name}/{nodePath}/drawingObjects

name = MyDocument_F.docx
drawingObject = { “Left”: 0, “Width”: 50, “Height”: 50 }
imageFile = environment.png
destFileName = MyDocument_D.docx
nodePath = sections/0/headersfooters/0/paragraphs/0

Default values of Width and Height attributes are 100.

Input Document: MyDocument_F.docx
Output Document: MyDocument_D.docx

Guys, We again followed all your recommendations but the result is not satisfactory. This has now become a make or break situation for us.I am sharing with you now all the resulting files along with the screenshots of API calls thru swagger interface.

Please go through them carefully and let us know what mistake are we doing as there are still many issues in the converted files.

Conversion : html → pdf
API used : Aspose.HTML Cloud - API References
Input file : comprehensive_report.zip (7.6 KB)

Parameter Values : image.png (34.3 KB)
Resulting Doc: report (3).pdf (108.9 KB)
Issues :

  • Unwanted page breaks
  • Html not top aligned in case of position and content (e.g. section 2 : question 2.1 )
  • page margins (top/bottom) are not consistent across pages

Conversion : PDF–> word
API used : Aspose.Pdf Cloud - API References
Input file : report (3).pdf (108.9 KB)
Parameter Values : image.png (30.9 KB)

Resulting Doc: report.zip (109.5 KB)

Issues :

  • Unwanted page breaks
  • Html not top aligned in case of position and content (e.g. section 2 : question 2.1 )
  • page margins (top/bottom) are not consistent across pages

Conversion : word–> word + header + text + logo + font dto
API used :

Input file : the word doc created above
Parameter Values : image.png (35.5 KB)
image.png (38.3 KB)
image.png (38.3 KB)
image.png (38.6 KB)
image.png (39.2 KB)

Resulting Doc: report-withHeaderTextlogoFont (4).zip (45.8 KB)

Issues :

  • Header and Section title overlapping each other
  • Not able to align text in header footer
  • Not able to align image in header
  • Not able to set page margins
  • And rest of the above issues are still coming

Guys, Please let us know if we can anyhow help you understand our requirements and problems we are going through other than this medium. we need to take a decision in coming days. Please be comprehensive about your recommendations and help us in achieving the desired result at the earliest.

Thanks
Awaiting your response

p.s. : I am attaching this folder which contains all the files (sample, intermediaries and final outcome)

files.zip (398.0 KB)

@abhisheknagarro

Conversion: html --> pdf
Issues:

  1. Unwanted page breaks
  2. Html not top aligned in case of position and content (e.g. section 2 : question 2.1 )
  3. page margins (top/bottom) are not consistent across pages

We are able to replicate the same issues on our end too. The issue is logged in our internal tracking software (HTMLCLOUD-630) and we are working hard to fix it at the earliest.

  • Not able to align text in header footer
  • Not able to align image in header

Unfortunately, at present, with Aspose.Words APIs you cannot align text and image in Header/Footer. The feature request has been logged in our tracking software as WORDSCLOUD-552 and we will update you here as soon as the requested feature is implemented.

We are sorry for the inconvenience caused.

Hi Team,

As you already know, We have been evaluating your product for the file conversions we need for our business.

Primarily, HTML → WORD and then eventually from WORD → PDF, However as communicated earlier by one of your team member that HTML → WORD is not possible directly and we may need to take a different route to achieve the same (HTML → PDF → WORD). Please refer
image.png (18.8 KB)

However, During our evaluation we have found that there are APIs available to get a html → word and also put objects as part of header/footer.

Aspose.Words Cloud - API References to convert HTML → WORD.

So, Can you please clear this to us if you officially support these APIs and they are production ready?

Regards,
Nipun Jain

Hi Team,

Any updates.

Regards,
Nipun Jain

@nipunjainindia

However, During our evaluation we have found that there are APIs available to get a html → word

Yes, we have an API to convert HTML to Word Aspose.Words Cloud - API References

However as communicated earlier by one of your team member that HTML -> WORD is not possible directly

I apologize for providing incorrect information earlier. I answered the query by just considering Aspose.HTML APIs which only provide API for HTML to PDF conversion. I forgot to mention that Aspose.Words provides an API to convert HTML to Word. In fact Aspose.Words provides an HtmlSaveOptions object which gives number of options for HTML to Word conversion:

< HtmlSaveOptions >
<!-- common part -->
< SaveFormat >{string}</ SaveFormat >
< FileName >{string}</ FileName >
<!-- specific part -->
< PrettyFormat >{true/false}</ PrettyFormat > <!-- default value = false -->
< AllowNegativeIndent >{true/false}</ AllowNegativeIndent > <!-- default value = false -->
< CssStyleSheetFileName >{string}</ CssStyleSheetFileName > <!-- default value = "" -->
< CssStyleSheetType >{Embedded/External/Inline}</ CssStyleSheetType > <!-- default value = Inline -->
< DocumentSplitCriteria >{ColumnBreak/HeadingParagraph/None/PageBreak/SectionBreak}</ DocumentSplitCriteria > <!-- default value = None -->
< DocumentSplitHeadingLevel >{number}</ DocumentSplitHeadingLevel > <!-- default value = 2 -->
< Encoding >{string}</ Encoding > <!-- default value = "UTF-8" -->
< ExportDocumentProperties >{true/false}</ ExportDocumentProperties > <!-- default value = false -->
< ExportFontsAsBase64 >{true/false}</ ExportFontsAsBase64 > <!-- default value = false -->
< ExportFontResources >{true/false}</ ExportFontResources > <!-- default value = false -->
< ExportHeadersFootersMode >{FirstSectionHeaderLastSectionFooter/None/PerSection}</ ExportHeadersFootersMode > <!-- default value = PerSection -->
< ExportImagesAsBase64 >{true/false}</ ExportImagesAsBase64 > <!-- default value = false -->
< ExportLanguageInformation >{true/false}</ ExportLanguageInformation > <!-- default value = false -->
< ExportListLabels >{Auto/AsInlineText/ByHtmlTags}</ ExportListLabels > <!-- default value = Auto -->
< ExportMetafileAsRaster >{true/false}</ ExportMetafileAsRaster > <!-- default value = true -->
< ExportOriginalUrlForLinkedImages >{true/false}</ ExportOriginalUrlForLinkedImages > <!-- default value = false-->
< ExportPageSetup >{true/false}</ ExportPageSetup > <!-- default value = false -->
< ExportPageMargins >{true/false}</ ExportPageMargins > <!-- default value = false -->
< ExportRelativeFontSize >{true/false}</ ExportRelativeFontSize > <!-- default value = false -->
< ExportRoundtripInformation >{true/false}</ ExportRoundtripInformation > <!-- default value = true -->
< ExportTextBoxAsSvg >{true/false}</ ExportTextBoxAsSvg > <!-- default value = false -->
< ExportTextInputFormFieldAsText >{true/false}</ ExportTextInputFormFieldAsText > <!-- default value = false -->
< ExportTocPageNumbers >{true/false}</ ExportTocPageNumbers > <!-- default value = false -->
< ExportXhtmlTransitional >{true/false}</ ExportXhtmlTransitional > <!-- default value = false -->
< FontResourcesSubsettingSizeThreshold >{number}</ FontResourcesSubsettingSizeThreshold > <!-- default value = 0 -->
< FontsFolder >{string}</ FontsFolder > <!-- default value = "" -->
< FontsFolderAlias >{string}</ FontsFolderAlias > <!-- default value = "" -->
< HtmlVersion >{Xhtml| Html5}</ HtmlVersion > <!-- default value = "Xhtml" -->
< ImageResolution >{number}</ ImageResolution > <!-- default value = 96 -->
< ImagesFolder >{string}</ ImagesFolder > <!-- default value = "" -->
< ImagesFolderAlias >{string}</ ImagesFolderAlias > <!-- default value = "" -->
< OfficeMathOutputMode >{Image/MathML/Text}</ OfficeMathOutputMode > <!-- default value = Image -->
< ResourceFolder >{string}</ ResourceFolder > <!-- default is an empty string -->
< ResourceFolderAlias >{string}</ ResourceFolderAlias > <!-- default is an empty string -->
< ScaleImageToShapeSize >{true/false}</ ScaleImageToShapeSize > <!-- default value = true -->
< TableWidthOutputMode >{All/None/RelativeOnly}</ TableWidthOutputMode > <!-- default value = All -->
< ExportDropDownFormFieldAsText >{true/false}</ ExportDropDownFormFieldAsText > <!-- default value = false -->
</ HtmlSaveOptions >

So, Can you please clear this to us if you officially support these APIs and they are production ready?

Yes, our APIs are production ready and we have a very strong customer base using these APIs.

@nipunjainindia

We want to share the update. Please note following issues are resolved in the Aspose.Words Cloud. Please feel free to contact us for any further assistance.

WORDSCLOUD-545: Blue Background is missing in PDF to Word conversion
WORDSCLOUD-552: Alignment of Text and Image in Header and Footer