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

Free Support Forum - aspose.com

Display Aspose HTML on webpage

Hi,
I’m using the function GetHTMLFromBookmark, which you so kindly provided me(code below), to pull the contents of a bookmark in HTML form. I then allow the users to edit the HTML & a - enter this info back into the document, b - display the info on a webpage.

private static string GetHtmlFromBookmark(string bookmarkName, Document doc, SaveFormat ThisSaveFormat)
{
    Document docClone = doc.Clone();
    Document doc1 = new Document();
    Bookmark mark = docClone.Range.Bookmarks[bookmarkName];
    Node node = mark.BookmarkStart.ParentNode;
    Node endNode = mark.BookmarkEnd.ParentNode.NextSibling;
    while (!node.Equals(endNode))
    {
        if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkStart))
        {
            Node child = (node as CompositeNode).FirstChild;
            Node endChild = mark.BookmarkStart.NextSibling;
            while (!child.Equals(endChild))
            {
                child = child.NextSibling;
                child.PreviousSibling.Remove();
            }
        }
        if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkEnd))
        {
            Node child = mark.BookmarkEnd;
            while (!child.Equals(child.ParentNode.LastChild))
            {
                child = child.NextSibling;
                child.PreviousSibling.Remove();
            }
            child.Remove();
        }
        doc1.FirstSection.Body.AppendChild(doc1.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting));
        node = node.NextSibling;
        if (node == null)
            break;
    }
    MemoryStream stream = new MemoryStream();
    doc1.Save(stream, ThisSaveFormat);
    string html = Encoding.UTF8.GetString(stream.GetBuffer());
    return html;
}

This returns the attached HTML. When displaying a webpage, it messes up the paragraph format. I was wondering how I can display this properly.
Thank you.

I figured out the issue here. Seems there was a master theme being implemented on the page which I was not aware of. Thank you.

Hello!
Thank you for your inquiry.
That’s nice if you have already found the solution. When you insert an HTML fragment its formatting in general depends on the context: what effective formatting affects the insertion point. If you are not satisfied with some formatting just try specifying corresponding attributes on the HTML nodes being inserted.
Regards,