Free Support Forum - aspose.com

.InsertBreak(BreakType.ParagraphBreak)

Hi,

I found .InsertBreak(BreakType.ParagraphBreak) is not working well since the new release of 3.1.2.0.

For the coding below, i suppose it will only put a line under "Employment History", and .InsertBreak(BreakType.ParagraphBreak) will actually seperate the next paragraph and borders(BorderType.Bottom).LineStyle = LineStyle.None will not underline the next paragraph.

But with new release, everything were underlined. Think .InsertBreak(BreakType.ParagraphBreak) did not work at all.

Please assist.

File attached.

EG code:

borders(BorderType.Bottom).LineStyle = LineStyle.Emboss3D

.InsertParagraph()

.Font.Bold = True

.Write("Employment History")

.Font.Bold = True

.InsertBreak(BreakType.ParagraphBreak)

borders(BorderType.Bottom).LineStyle = LineStyle.None

Hi Aspose Team,

Would you be able to assist on problem mentioned? Pls notify me If you are looking into it.

Thanks.

regards,

kllee1983

Sorry for the delay, support requests that come at different times of day can be handled by different Aspose staff in different timezones. We will certainly try to reproduce the issue and help or rectify it if needed in the next few hours.

I've found why its happening.

In Aspose.Word 3.x, DocumentBuilder.ParagraphFormat property actually "attaches" to the object that represents formatting properties of the current paragraph. Therefore, if the cursor is moved to another paragraph (and this is the case with inserting a paragraph break), the ParagraphFormat property is "reattached" to a different object.

Borders b1 = builder.ParagraphFormat.Borders;

//This moves the cursor to the newly inserted paragraph.
builder.InsertBreak(BreakType.ParagraphBreak);

//b2 is a different object from b1 in Aspose.Word 3.x because ParagraphFormat and Borders are now attached to a different paragraph.
Borders b2 = builder.ParagraphFormat.Borders;

//It is true, they are different objects.
Debug.Assert(b1 != b2);

-----

So the problem is that you cache the pointer to ParagraphFormat.Borders in a local variable called borders. When the cursor in the document builder moves to another paragraph, your borders variable remains pointing to the original (first) paragraph.

I think this is a problem in Aspose.Word since it should not have broken the backward compatibility this way and we will try to fix it. To workaround in the meantime, just don't cache ParagraphFormat.Borders in a local variable.

DocumentBuilder b = new DocumentBuilder();

b.ParagraphFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Emboss3D;

b.Font.Bold = true;

b.Write("Employment History");

b.InsertBreak(BreakType.ParagraphBreak);

b.ParagraphFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.None;

b.Writeln("Hello");

Will try out, think it should help me a lot.

Thanks a million!!

regards,

kllee1983