Hi, I have a document with custom style name. When I save DOC file into HTML, I lose all the custom style names. Is there a way to preserve the style names like this?
Thanks
Hi, I have a document with custom style name. When I save DOC file into HTML, I lose all the custom style names. Is there a way to preserve the style names like this?
Thanks
Hi Alex,
Thanks for your inquiry. Please use the HtmlSaveOptions.setCssStyleSheetType* method to specify how CSS (Cascading Style Sheet) styles are exported to HTML, MHTML or EPUB. Yes, you can export custom styles of MS Word document into Html by using Aspose.Words. Please use the following code snippet to achieve your requirements (export custom styles as ).
Document doc = new Document(MyDir + "in.doc");
HtmlSaveOptions option = new HtmlSaveOptions();
option.setCssStyleSheetType(CssStyleSheetType.EMBEDDED);
doc.save(MyDir + "Out.html", option);
Moreover, please note that Aspose.Words mimics the same behavior as MS Word do. Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting here:
https://docs.aspose.com/words/java/save-in-the-html-html-xhtml-mhtml-format/
Hi Tahir,
I think you misunderstood me. I would like to preserve names of custom styles. In word, I’m allowed to create custom styles, ie, myStyle. When I export to HTML, Aspose converts the styles into css but losing the name.
So the question is if it’s possible to preserve the name in either style below
or
Hi Alex,
Thanks for your inquiry. If your document contains a custom style with name e.g ‘myStyle’, Aspose.Words export the style in output html as shown below.
Style type itself is not exported to CSS but it is implied by the specific attributes exported to that style. There is a setting to export paragraph and character styles as inline CSS (style), embedded or linked CSS style sheet (class). Please check CssStyleSheetType.
<style type="text/css">
.myStyle { font-family:Verdana; font-size:22pt; line-height:115%; margin-bottom:10pt }
</style>
Paragraph
1
In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.8.0) from here and let us know how it goes on your side. If the problem still remains, please attach your input Word document here for testing. I will investigate the issue on my side and provide you more information.