We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Convert doc to HTML

Is it possible to get DocIO to save to HTML as one file per page?

The default is one HTML file for the entire document.



3 Replies

SK Sathish K Syncfusion Team September 30, 2015 05:56 AM UTC

Hi Gary,

Thank you for contacting Syncfusion support.

If your requirement is to save each and every pages of the Word document as separate HTML file, then kindly keep each and every pages as separate sections in the Word document and iterate each sections from the Word document then save them as separate HTML files using the below code example.

Code example:
//Opens the source document

WordDocument sourceDocument = new WordDocument(@"File location");

int i = 1;

//Iterates the sections

foreach (WSection section in sourceDocument.Sections)

{              

//Instatiating the new WordDocument object

WordDocument htmlDocument = new WordDocument();

//Add the current section to the new Word document

htmlDocument.Sections.Add(section.Clone());

//Saves the document.

htmlDocument.Save("DocIOHTML" + i.ToString() + ".html", FormatType.Html);

//Closing WordDocument instance

htmlDocument.Close();

i++;

}

//Closing source document instance
sourceDocument.Close();

Regards,
Sathish



GR Gary Rumble September 30, 2015 03:42 PM UTC

Unfortunately, I don't have any control over the doc file, it's provided by someone else.

Currently, it looks like the file has one section, but multiple pages, so the code below doesn't work.

I can use the render as images to get individual pages, but save to HTML just gives me one file.



DV Divyalakshmi Vasudevan Syncfusion Team October 1, 2015 08:17 AM UTC

Hi Gary,

Thank you for your update.


The Word document is a flow document in which contents will not be preserved page by page; instead the contents will be preserved sequentially section by section. Each section may extend to various pages based on its contents like table, text, images etc. Word viewer/editor renders the contents of the Word document page by page dynamically when opened for viewing or editing and these page wise rendered information will not be preserved in the document level as per the Word file format specification. Whereas Essential DocIO is a non UI component that provides a full-fledged document object model to manipulate the Word document contents. Hence currently it is not feasible to meet your requirement.


Please let us know in case of any other questions.

Regards,
Divyalakshmi V


Loader.
Live Chat Icon For mobile
Up arrow icon