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

Free Support Forum - aspose.com

How to set properties of a Horizontal Rule

Hello,

I am using builder.InsertHorizontalRule() to insert the horizontal rule in the document and I would like to set additional attributes for this rule. I find the inserted shape (it would be good if the metod returned the shape) and set the width or horizontal alignment, however in the resulting document the created horizontal rule always has 100% width and is left aligned. Setting height or color of this element works properly on the other hand. Could you please tell me how can I set the width and alignment for the hr?

Please find the example solution and expected result (in hr_expected file) attached.

Thanks,
AnnaHrTestApp.zip (28.1 KB)

@acturisaspose

Thanks for your inquiry. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-18182 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

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

@acturisaspose,

Regarding WORDSNET-18182, it is to update you that we have added a new public property named Shape.HorizontalRuleFormat, a new public class HorizontalRuleFormat and a new public enum HorizontalRuleAlignment in Aspose.Words. Sample usage is as follows:

DocumentBuilder builder = new DocumentBuilder();

Shape shape = builder.InsertHorizontalRule();
HorizontalRuleFormat horizontalRuleFormat = shape.HorizontalRuleFormat;

horizontalRuleFormat.Alignment = HorizontalRuleAlignment.Center;
horizontalRuleFormat.WidthPercent = 70;
horizontalRuleFormat.Height = 3;
horizontalRuleFormat.Color = Color.Blue;
horizontalRuleFormat.NoShade = true;

builder.Document.Save("HorizontalRuleFormat.docx");

Hope, this helps in achieving what you were looking for.

Thank you Awais, that’s very helpful.

Thanks,
Mateusz