How to add Vertical line in a shape

Aspose provides HorizontalRuleFormat to create a horizontal line. But I want to create a vertical line. Tried using HorizontalRuleFormat for same but setWidthInPercent through exception for valid range.
Is this the correct way?
If not how can we draw a vertical line in shape?

GroupShape g1 = new GroupShape(document);
g1.setBounds(new Rectangle2D.Float(0f, 0f, (float)builder.getPageSetup().getPageWidth(), (float)builder.getPageSetup().getPageHeight()));
g1.setCoordSize(new Dimension((int)builder.getPageSetup().getPageWidth(), (int)builder.getPageSetup().getPageHeight()));
g1.setCoordOrigin(new Point(0, 0));

g1.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
g1.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);

document.getLastSection().getBody().getLastParagraph().appendChild(g1);

Shape shape2 = new Shape(document, ShapeType.TEXT_BOX);
Paragraph paragraph2 = new Paragraph(document);
Run run2 = new Run(document, "");
paragraph2.appendChild(run2);
shape2.appendChild(paragraph2);
builder.moveTo(run2);
Shape line2 = builder.insertHorizontalRule();
HorizontalRuleFormat verticalRuleFormat = line2.getHorizontalRuleFormat();
verticalRuleFormat.setWidthPercent(0.74);
verticalRuleFormat.setHeight(114);
verticalRuleFormat.setColor(Color.RED);
verticalRuleFormat.setNoShade(true);
TextBox textbox2 = shape2.getTextBox();
textbox2.setInternalMarginBottom(0);
textbox2.setInternalMarginLeft(0);
textbox2.setInternalMarginRight(0);
textbox2.setInternalMarginTop(0);
shape2.setTop(100);
shape2.setLeft(60);
shape2.setWidth(5);
shape2.setHeight(114);
g1.appendChild(shape2);

@aishwarya12joshi Please see the following code that create a simple vertical line:

Document doc = new Document();

Shape verticalLine = new Shape(doc, ShapeType.LINE);
verticalLine.setHeight(doc.getFirstSection().getPageSetup().getPageHeight());
verticalLine.setWidth(0);
verticalLine.getStroke().setWeight(1);
verticalLine.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
verticalLine.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
verticalLine.setVerticalAlignment(VerticalAlignment.CENTER);
verticalLine.setLeft(100);

doc.getFirstSection().getBody().getFirstParagraph().appendChild(verticalLine);
doc.save("C:\\Temp\\out.docx");

out.docx (7.3 KB)

Yes this worked. Thank you!!

1 Like