Docx to html convertion again html to docx (after changes)

I am converting word document to html (i want same style (fonts,color,table of content,header,footer,paging etc…),in that html i will add some text some places from browser interface again I want to convert from html to word document (I need same style of source document final document).
can you please provide code for this.

I have written code like this for converting docx to html

Aspose.Words.License lic = new Aspose.Words.License();
lic.SetLicense("Aspose.Words.lic");
Document doc = new Document(HttpContext.Current.Server.MapPath(MyDir + filename));
string html = "";
//var options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html)
//{
//    ImageSavingCallback = new HandleImageSaving(),
//};
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.ExportImagesAsBase64 = true;
saveOptions.PrettyFormat = true;
saveOptions.ExportPageSetup = true;
saveOptions.ExportTocPageNumbers = true;
// saveOptions.ExportHeadersFooters = true;
saveOptions.CssStyleSheetType = CssStyleSheetType.Embedded;
string dynamichtmlfile = "dynamicfile_" + Guid.NewGuid() + ".html";
doc.Save(HttpContext.Current.Server.MapPath(MyDir + dynamichtmlfile), saveOptions);
using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath(MyDir + dynamichtmlfile)))
    html = reader.ReadToEnd();

return html;

@raju.net

Please ZIP and attach your input HTML, problematic and expected output DOCX files here for testing. We will investigate the issue and provide you more information on it.

Aspose.zip (206.8 KB)

I uploaded docx and html files .
My requirement is : first I need to convert from docx to html string(with all styles and paging,header and footer) ,I will send this html string to browser and load this html data in a div (with contenteditble ->we can modify data here) again I will send this html to server then i
nedd to convert this html data to docx file same as our souce document styles ,header,footer all styles .
,my current code paging,header and footer missing.

1. Docx to html (with all styles ,header ,footer ,paging)
2 html to docx(after changing some minor changes )

Note:I don’t want create html file only html sting ,this html string I wll send to frontend(to browser) ,after change some content again I will send this html to server for creating docx file

@raju.net

Please note that HTML and Word file formats are quite different. So, sometimes it is hard to achieve 100% fidelity. Moreover, it is hard to meaningfully output headers and footers to HTML because HTML is not paginated. Aspose.Words exports only primary headers and footers at the beginning and the end of each section by default.

Regarding conversion from DOCX to HTML string and HTML string to DOCX, you can achieve it using following code example. Hope this helps you.

Document doc1 = new Document(MyDir + "input.docx");
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.ExportImagesAsBase64 = true;
saveOptions.PrettyFormat = true;
saveOptions.ExportPageSetup = true;
saveOptions.ExportTocPageNumbers = true;
String html = doc1.ToString(saveOptions);

// convert string to stream
byte[] byteArray = Encoding.UTF8.GetBytes(html);
MemoryStream stream = new MemoryStream(byteArray);
                
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Html;
Document doc2 = new Document(stream, loadOptions);
doc2.Save(MyDir + "21.5.docx");
1 Like