Free Support Forum - aspose.com

Can aspose.words convert a Paragraph's text into html?

Hi,

I am trying to convert different paragraphs from a .doc to html text( not the full document to html). Is that possible?

Thanks,
Mircea

Hi

Thanks for your inquiry. Unfortunately, there is no direct way to get HTML of the particular node. However, you can achieve this. In your case, you should just copy particular node into a separate, empty document and then convert this document to HTML. For example, see the following code:

// Open document.

Document doc = new Document(@"Test001\in.doc");

// Create an empty intermediate document.

Document temp = new Document();

// Copy the first paragraph of source document into temp document.

temp.FirstSection.Body.AppendChild(temp.ImportNode(doc.FirstSection.Body.FirstParagraph, true, ImportFormatMode.KeepSourceFormatting));

// Get HTML string, which representd the temporary document.

string html = ConvertDocumentToHtml(temp);

================================================================

public string ConvertDocumentToHtml(Document doc)

{

string html = string.Empty;

// Save docuemnt to MemoryStream in Hml format

using (MemoryStream htmlStream = new MemoryStream())

{

doc.Save(htmlStream, SaveFormat.Html);

// Get Html string

html = Encoding.UTF8.GetString(htmlStream.GetBuffer(), 0, (int)htmlStream.Length);

}

// There could be BOM at the beggining of the string.

// We should remove it from the string.

while (html[0]!='<')

html = html.Substring(1);

return html;

}

Hope this helps.

Best regards.

The issues you have found earlier (filed as WORDSNET-5430) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(3)