Bookmark and incorrect font size!

Ive just been trying the trial component for 2 hours… and I must say it is really awesome! In fact, after 2hours of playing around with it, I decided to buy the Aspose.Word ans Aspose.Pdf compoment! Thanks to you guys!

Here is my problem:

When I try to change the .Text property of a bookmark, the font is like Arial 35pt which is not the desired font.

I kinda have 2 questions here:

  1. Why doesn’t it take the font at the bookmark’s place?

  2. Is there a way I can choose my font so I can set it back to something I want?
    2b. If so, how?

Here is what I did so far:

Aspose.Word.Document dPart1 = new Aspose.Word.Document(@"c:\part1.doc");
Aspose.Word.Bookmarks bPart1 = dPart1.Range.Bookmarks;
bPart1["FicheA"].Text = "X";

Then save the document. The ‘X’ does place itself at the right place, but way too big!

Thanks for helping!

If you do it this way, the inserted text takes on formatting attributes available at the bookmark in the document. You must have something formatted with Arial 35 at or near the bookmark (maybe a space character).

Another way you could try is:

DocumentBuilder.MoveToBookmark("mybookmark");
DocumentBuilder.Font.Size = 10;
DocumentBuilder.Write("Hello");

This way you do can much more than inserting just a piece of text.

Thanks, I like that!

Very simple and straight foward!

Thank you very much!

Hi

I’m new to aspose.word and I dont understand how to create a bookmark in a word document to move the cursor posistion.

Similar to the example above I would like to insert merge fields
(DocumentBuilder.InsertField) in various locations within the document. How do you create book marks (“mybookmark”)?

For example:

I have a word template document with text created by a user using aspose.textbox.web.
The document has bogus mergefields (chr(171) & Address_1 & Chr(189)). I want to find the bogus field in the document and perform
builder.InsertField(“MERGEFIELD MyFieldName * MERGEFORMAT”, “”)
throughout the entire document.
Any Ideas

thanks

Adam

Hi Adam,

Thank you for considering Aspose.

If you need to insert a bookmark in a document, use the DocumentBuilder.StartBookmark and DocumentBuilder.EndBookmark methods. Moving to a separate bookmark is performed with the DocumentBuilder.MoveToBookmark method.

Regarding your case, isn’t it possible to manually replace the pseudo-fields with the bookmarks or merge fields? If not, maybe the most suitable way for you is implementing MergeFieldEventHandler and using the Range.Replace method although I don’t think this is very elegant.