create bookmark "ex novo"

Originally Posted 11 July 2017, 4:05 am EST

  • Originally Posted 11 July 2017, 4:05 am EST

    good morning.
    in my project I must add some data marked by bookmark in word documents. The documents changes, and so I cannot construct a "skeleton" with the bookmark I need.
    Can I add bookmark to the body of document regardless of word initial document? do you have some sample?
    I work with VS2015 / win10 (vb.net)

    thank you
  • Reply

    Hi,

    You can add bookmarks in a word document using the AddBookmark, AddBookmarkStart and AddBookmarkEnd methods. You can learn more about them from the Public Methods section in the below documentation link:

    http://helpcentral.componentone.com/nethelp/C1wordWin/C1.C1Word.4~C1.C1Word.C1WordDocument_members.html

    To make a bookmark to have text "ex novo", you may traverse C1Word's MainSection.Content to check if the current text is "RtfBookmarkStart" or "RtfBookmarkEnd" and then, add the text accordingly. A sample has been attached for your reference.
    We are a little unsure about this: "Can I add bookmark to the body of document regardless of word initial document?". In case the provided solution does not meet your requirements, we request you to explain your use case in detail, so that we can assist you further.

    Regards,
    Esha

    2017/07/prj_C1Word_Bookmark.zip
  • Reply

    Thank you for your answer. I have tried your sample, and it add bookmark... but lose header and footer. I send you my sample docx ("vuota.docx") and the result of the program test ("simple.docx"). I have two other question: as You can see in my "Button1_click", I have tried to change font style, but this means to add a new paragraph. can I chang font without add paragraph (paragraphs adds lines). the other question is e curiosity: why "addparagraph" doesn't add the markers like "addbookmarkstart" and "Addbookmarkend"?
    Thank again for you patience.
    2017/07/vuota.docx

    2017/07/simple.docx

    2017/07/button1_click.txt
  • Reply

    Hi,

    We are discussing your requirements with the developers and will get back to you once we hear from them.

    Regards,
    Esha
  • Reply

    Hi,

    1. You can change font for an existing paragraph using the below code snippet:


    For Each obj In C1WordDocument1.MainSection.Header
    Dim paragraph As RtfParagraph = TryCast(obj, RtfParagraph)
    If Not paragraph Is Nothing Then
    paragraph.Font = font
    End If
    Next

    You may also use a paragraph context (RtfString objects).

    2. AddParagraph method not adding the markers is a limitation as of now.

    Regards,
    Esha
  • Reply

    Ok, thank you, but what about the disappearing of header / footer? FYI, i recall the problem: I have some documents, with header and/or footer. I must insert some bookmarks in these, some of this with different font (Bcode, for example). When I have opened the results doc, header / footer has gone... Thank You again. NB - in my previous post there are my tests
  • Reply

    Hi,

    In your sample, bookmark text "ex novo" is not shown in the output because it is covered with the image "La Presidente" in the "vuota.docx". Please refer to the attached output file for more clarity.

    Regards,
    Esha
    2017/08/output.docx
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels