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

Free Support Forum - aspose.com

Need to replace bookmark with HTML formatted text

Hi,


I need to replace a bookmark on existing doc file with html formatted text from a rich text box. Please help, its very urgent.

Thanks

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You need to use MoveToBookmark() method to move cursor to desired bookmark and then InsertHtml() method for inserting html. Please refer to the following articles for further details. Hopefully it will serve the purpose.

http://www.aspose.com/docs/display/wordsnet/MoveToBookmark+Method

http://www.aspose.com/docs/display/wordsnet/Inserting+Document+Elements

Please feel free to contact us for any further assitacne.

Best Regards,

I tried this method and it replaced bookmark with this


Admission
Information:

  • Date of
    Admission:

    05/24/2012
  • Date of
    Discharge:

    05/25/2012

Provider
Information:

  • Hopkins Discharge Attending: Dr. Kim Reiss,
    MD
  • Hopkins Discharge Attending Tel
    No:
    443-287-3127
  • Primary
    Care Provider:

    Christine Fleurimond, MD
  • Primary Care
    Provider Tel No:
    410-383-8300

Medications
(Verify medication names with your
Pharmacist)

  • Vitamin, Multi 1 tablet Daily By
    mouth.
  • Ferrous
    Sulfate 325 mg With meals By
    mouth.
  • Vitamin B12 1000 mcg by mouth
    daily

Discharge Patient
To:

  • Home

Appointments:

  • Provider’s
    Name:
    Total Healthcare Division Street

Discharge
Diets:

  • Diet Instructions
    Regular

Discharge
Activities/Restrictions:

  • Resume normal activity
    as tolerated

Other
Issues:

  • - Please review the following: IF YOU NEED HELP FROM A
    MEMBER OF THE<o:p></o:p>

HOSPITALIST TEAM FOLLOWING YOUR DISCHARGE TO CLARIFY YOUR POST-DISCHARGE

PLANS, MEDICATIONS OR TREATMENTS, PLEASE CALL MAGGIE NEELY (CASE MANAGER)

AT 410-502-5302. IF YOU NEED HELP DURING NON-BUSINESS HOURS, CALL THE

HOSPITALIST UNIT FRONT DESK AT 443-287-3127. IF IT IS AN EMERGENCY, CALL

911.

  • PLEASE BE SURE TO TAKE ALL MEDICATIONS AND YOUR BLUE DISCHARGE FOLDER WITH
  • <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>YOU, WHEN YOU GO IN TO SEE
    YOUR PRIMARY DOCTOR.

    Authored/Entered By:
    Williams, Lisa © Entered On 2012-05-25
    12:41

    • Authored/Entered By:
      Williams, Lisa © Entered On 2012-05-25
      12:41
    • Last Edited/Revised By: Reiss
      Binder, Kim (MD) Entered On 2012-05-25 15:52
    <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>
    <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>
    <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>I need formatted html dont want to show the tags on the doucment. Hope I get a solution asap.
    <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>
    <span style=“font-size:16.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
    mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Calibri;
    position:relative;top:-.5pt;mso-text-raise:.5pt;mso-ansi-language:EN-US;
    mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Thanks

    Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    Thanks for your inquiry. Please check following code snippet, for moving cursor to a specific bookmark and to insert formatted html. Hopefully it will serve the purpose.

    Document doc = new Document(MyDir+"bookmarktest.doc");

    DocumentBuilder builder= new DocumentBuilder(doc);

    builder.MoveToBookmark("bm_1",true,false);

    builder.InsertHtml("

    Admission Information:

    • Date of Admission:05/24/2012
    • Date of Discharge: 05/25/2012

    Provider Information:

    • Hopkins Discharge Attending:Dr. Kim Reiss, MD
    • Hopkins Discharge Attending Tel No: 443-287-3127
    • Primary Care Provider:Christine Fleurimond, MD
    • "
    );

    doc.Save(MyDir+"out.doc");

    Please feel free to contact us for any further assistance.

    Best Regards,

    The string is coming from FreeRichText box .


    db.MoveToBookmark(“BookMarkMedicine”);
    db.InsertHtml(FreeTextBox1.Text);

    doc.Save(Response, “Report Out.doc”, Aspose.Words.ContentDisposition.Inline, null);

    Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    Thanks for your inquiry. Could you please share your sample working solution? So we will have a close look into it and suggest you solution accordingly.

    Please feel free to contact us for any further assistance.

    Best Regards,

    Hi Tilal,


    vSaral is asking for How to get a formatted Text in
    in bookmark1.Text
    Suppose if we assigned a bookmark to a formatted text …and made some formatting changes .After that How to assign this formatted text to bookmark.Text???
    or
    formattedText.Replace(FormattedText,bookmark.Text)…

    I also need to know Is it possible ?

    Thanks
    sreejesh



    Hi Sreejesh,

    Thanks for your inquiry.

    The Bookmark.Text property gets the text
    enclosed in the bookmark without formatting. If you want to get the
    formatted text inside a bookmark, please extract the content from a bookmark using the code shared in following documentation link:
    http://www.aspose.com/docs/display/wordsnet/Extract+Content+from+a+Bookmark

    In your case, you need to use MoveToBookmark method to move cursor to desired bookmark and use InsertDocument method to insert the extracted contents to bookmark. Please check the code of InsertDocument method from here:
    http://www.aspose.com/docs/display/wordsnet/How+to++Insert+a+Document+into+another+Document

    Hope this answers your query. Please let us know if you have any more queries.

    Hi,


    I am trying to insert HTML into bookmark but I am seeing it is being inserted all time outside of the bookmark. I am using following code

    // Retrieve the bookmark.
    var bookmark = wordDoc.Range.Bookmarks[bookmarkName];

    if (!bookmark.IsNull())
    {
    // Create a document builder so we can insert the new value as html.
    //wordDoc.Range.Bookmarks[bookmark.Name].Text = string.Empty;
    var documentBuilder = new Aspose.Words.DocumentBuilder(wordDoc);
    documentBuilder.MoveToBookmark(bookmark.Name, true, false);
    documentBuilder.Writeln(bookmarkValue);
    }

    I am using Alfresco version v4.0.30319. I am attaching word document where you can see result.

    Please guide me in this issue.

    Regards,
    Robert
    Hi Dinesh,

    Thanks for your inquiry. Could you please share bookmark name here for testing? We will investigate the issue on our side and provide you more information.

    Moreover, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

    We have used following code example to test your scenario and have not found any issue with output document.

    Document wordDoc = new Document(MyDir + "TestResearch_T_F.docx");

    var bookmark = wordDoc.Range.Bookmarks["bmkDocAuthor"];

    wordDoc.Range.Bookmarks[bookmark.Name].Text = string.Empty;

    var documentBuilder = new Aspose.Words.DocumentBuilder(wordDoc);

    documentBuilder.MoveToBookmark(bookmark.Name, true, false);

    documentBuilder.InsertHtml("new text");

    wordDoc.Save(MyDir + "Out.docx");

    Hi,


    Please find expected word document and sample template as an attachment. My issue is when I insert html in bookmark it alltime display outside of the bookmark. I have used all option combination for “InsertHtml” method.As html is inserting outside of bookmark so user is not able to edit it. I given option that text inside the bookmark user can edit it.

    I created bookmark with protection with paragraph so user can not delete bookmark but can edit text between bookmark. In my sample template I given two bookmark “bmkSupportingAnalysis” this bookmark is protected and user cannot delete it.

    Other bookmark “bmkTest” is unprotected and so user can delete it. Template is protected and password is “test”.

    Please provide solution for this, that after inserting html user should be able to edit it.

    Regards,
    Robert
    Hi Robert,

    Thanks for sharing the detail. In your case, we suggest you please insert the html contents between EditableRangeStart and EditableRangeEnd. Please check following code example for your kind reference. Hope this helps you.

    Document wordDoc = new Document(MyDir + "SampleTemplate.docx");

    var bookmark = wordDoc.Range.Bookmarks["bmkSupportingAnalysis"];

    var documentBuilder = new Aspose.Words.DocumentBuilder(wordDoc);

    if(bookmark.BookmarkStart.NextSibling.NodeType == NodeType.EditableRangeStart)

    {

    EditableRangeStart ers = (EditableRangeStart)bookmark.BookmarkStart.NextSibling;

    documentBuilder.MoveTo(ers.EditableRange.EditableRangeEnd);

    }

    documentBuilder.InsertHtml("new text");

    wordDoc.Save(MyDir + "Out.docx");

    Hi Tahir,


    Thanks your solution is working for me. I am seeing only one issue that when I am inserting html into bookmark seeing two blank line in starting while HTML didn’t have blank lines. Please see in attached document.

    Regards,
    Robert
    Hi Robert,

    Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. There are thee empty paragraph inside bookmark "bmkSupportingAnalysis". Please check the attached image for detail. We suggest you please remove the empty paragraphs between BookmarkStart and BookmarkEnd nodes in your template document.