I am getting the HTML, by pulling the original contents of the bookmark using the GetHTMLFromBookmark function which I found on the forums(see code below).
This returns a HTML string(see below).
What I need to do is - 1 - pull the text from a bookmark. 2 - allow user on the web to edit this text(this is done on a webpage, using FreeTextBox, and works nicely). 3 - insert the updated HTML back into the document.
How would I go about doing this, so that the formatting of the final document looks ok, without getting messed up?
HTML String returned:
String BodyHTML = @"<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /><meta name=""generator"" content=""Aspose.Words for .NET 5.1.0.0"" /><title></title></head><body><div class=""Section1""><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:252pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; "">May 19, 2008</span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><a name=""Addressee""></a><span style=""font-family:'Times New Roman'; font-size:12pt; "">Dr. Jay Vida </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; "">Lakewood , NJ 08701</span></p><p style=""margin-left:216pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; text-indent:36pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; "">Re:</span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; "">Last</span><span style=""font-family:'Times New Roman'; font-size:12pt; "">, </span><span style=""font-family:'Times New Roman'; font-size:12pt; "">First</span></p><p style=""margin-left:216pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; text-indent:36pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; "">Dear </span><a name=""Start""></a></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; "">Many thanks for this kind referral.</span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span><span style=""font-family:'Times New Roman'; font-size:12pt; "">Sincerely,</span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p><p style=""margin-left:0pt; margin-right:0pt; margin-top:0pt; margin-bottom:0pt; ""><span style=""font-family:'Times New Roman'; font-size:12pt; ""> </span></p></div></body></html>";
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;
}