Free Support Forum - aspose.com

Create DOCX from HTML

I’m creating docx document from HTML string using,


Document asposeDoc = new Document();
DocumentBuilder asposeDocB = new DocumentBuilder(asposeDoc);
asposeDocB.InsertHtml(htmlString);
asposeDoc.Save(“test11.docx”, SaveFormat.Docx);

This is working fine. But here my HTML string is a concatenation of 6 differrent HTML pages. And I would like to have the HTML to start on the new page.
Please let me know if this is possible and provide sample code.

Thank you!

@naru.shiva,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your input Word document (if any)
  • Save HTML string in .html file and share the HTML file.
  • Aspose.Words generated DOCX file showing the undesired behavior.
  • Your expected Word document showing the correct output. Please create this document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

Dear Awais, thank you for the response. I will probably try to explain with an example instead of posting the files.

c# code:

string htmlString = "< html >test page one< / html > " + “< html >test page two< / html >” + “< html >test page three< / html >” + “< html >test page four< / html >”;

Document asposeDoc = new Document();
DocumentBuilder asposeDocB = new DocumentBuilder(asposeDoc);
asposeDocB.InsertHtml(htmlString );
asposeDoc.Save(wordFilePath, SaveFormat.Docx);

I would like to have a page break after every page in the output word document (docx).
Currently it is printing continuously.

Also would it be possible to changes html textboxes and html drop-downs to plain labels?

Thank you,
Shiva

@naru.shiva,

Please try using the following code:

string pageBreak = "<br style='page-break-before: always'>";
string htmlString = "<html>test page one</html> " + pageBreak + "<html> test page two</html>" + pageBreak + "<html> test page three</html>" + pageBreak + "<html> test page four</html>";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(htmlString);
doc.Save(MyDir + @"18.5.docx", SaveFormat.Docx); 

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your input Word document (if any)
  • Save HTML string in .html file and share the HTML file.
  • Aspose.Words generated DOCX file showing the undesired behavior.
  • Your expected Word document showing the correct output. Please create this document by using MS Word.

As soon as you get these pieces of information ready, we will start further investigation into your above issue and provide you more information. Thanks for your cooperation.

Hi, Yes I figured out the page-break-before part myself after I posted the question.

Thank you.

@naru.shiva,

It is great that you were able to find what you were looking for. Please let us know any time you have any further queries.