We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add CSS to an Html document when saving?

I am converting a word document to Html. I want to apply some CSS to the Html document while saving it. How can I do that?

Thank you.

@p.ghimire,

Thanks for your inquiry. Unfortunately, Aspose.Words does not provide API to apply CSS while saving Word document to HTML. In your case, we suggest you following solution.

  1. Modify the styles of Word document’s or apply direct formatting to text using Run.Font property.
  2. Save the document to HTML.

Please read following article. Hope this helps you.
Using DocumentBuilder to Modify a Document Easily

Thank you for the suggestion, Tahir. I wasn’t however, able to set the width of the document. Is there a method/property I can use to set the document width?

Thank you.

@p.ghimire,

Thanks for your inquiry. Please use PageSetup.PageWidth property to get or set the width of the page in points. Following code example show how to use this property.

If you still face problem, please share your input and expected output documents. We will then provide you more information on this.

Document doc = new Document(MyDir + "input.docx");

foreach (Section section in doc.Sections)
{
    section.PageSetup.PageWidth = 600;
}

doc.Save(MyDir + "output.docx");