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

Free Support Forum - aspose.com

Different font if writing text before floating image

Hello Community,

I have different behavior when do operations in Word and Aspose

for attached example I run following code:
var folder = @“c:\dev”;
var doc = new Document(Path.Combine(folder, “imagefont.docx”));
var docBuilder = new DocumentBuilder(doc);
docBuilder.MoveToBookmark(“TEST_B”, false,true);
docBuilder.Write(“TEST_B”);
docBuilder.Document.Save(Path.Combine(folder, “imagefont-result.docx”));

In this case Run blocks with texts used Arial font, but floating image used Times New Roman
in MSWord inserted cursor after bookmark have Arial font
in Aspose text inherits font settings from image and result is in Times New Roman
How can I easily use previous Run block font like Word,

BR

Hi Daniel,


Thanks for your inquiry. You are getting the expected behavior of Aspose.Words. Please open the document in MS Word, click on the image, and write some text. The font of the text will be “Times New Roman”. Please note that the default value of DocumentBuilder.Font.Name is “Times New Roman”.

You can get the desired output by moving the cursor to the first Run node of Paragraph. Please check the following highlighted code snippet. Hope this helps you.

var doc = new Document(MyDir + “imagefont.docx”);<o:p></o:p>

var docBuilder = new DocumentBuilder(doc);

docBuilder.MoveTo(doc.FirstSection.Body.FirstParagraph.Runs[0]);

docBuilder.Write("TEST_B");

docBuilder.Document.Save(MyDir + "17.5.docx");

Hi Tahir,

Thanks for your fast reply and example!
Moving to first Run of paragraph is not what I can use.
This not working in more complex cases and looking for more generic solution.

Problem not related to only floated images but inline images too.

Main goal what i expect is:
navigate cursor after bookmark and insert text in same styles as MsWord result.

In next attached doc we can see line with bookmark TEST_B and image inserted after that.
Moving cursor too bookmark using MsWord shows AGaramond font from previous run of paragraph.
Aspose in same situation (‘docBuilder.MoveToBookmark(“TEST_B”, false, true)’ ) takes font from next run with image (Times New Roman).

Source docs are user-created and can contain strange formatting like examples provided.

Could you help with generic solution for this case?

BR, D

Hi Daniel,

Thanks for your inquiry. Please try following code example. Hope this helps you.

var doc = new Document(MyDir + "imagefont.docx");

var docBuilder = new DocumentBuilder(doc);

docBuilder.MoveToBookmark("TEST_B", true, true);

docBuilder.Write("TEST_B");

docBuilder.Document.Save(MyDir + "17.5.docx");

Hello Tahir,

Thanks for reply. Moving before of bookmark’s end locates cursor in bookmark.
In your written text is located between bookmarkStart and bookmarkEnd markers, but default behavior of msWord writes text after tags.

expected:
[]TEST_B
observed:
[TEST_B]
How we can deal with that keeping docBuilder.MoveToBookmark(“TEST_B”, false, true); as is?

BR, D
Hi Daniel,

Thanks for your inquiry.

We have logged this problem in our issue tracking system as WORDSNET-15423. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

@zurvege,

The issues you have found earlier (filed as WORDSNET-15423) have been fixed in this Aspose.Words for .NET 17.7 update and this Aspose.Words for Java 17.7 update.