Free Support Forum -

Draw a line

I need a horizontal line. The line needs to adjust to the width of the page, such as in the case of Portrait or Landscape.

I need the effect of Underline and Overline. I tried this, but there is not enough vertical space between the text and lines. I need another idea.


Thanks for your interest in our products and sorry for replying you late.

In order to add a horizontal line, you may simply try using the Line class of Aspose.Pdf.Generator namespace. Please take a look over following code snippet in which a horizontal line equivalent to page width is added. It works irrespective of the page orientation.


//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Add a section to the Pdf document
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
// set left and right margin information for section object
sec1.PageInfo.Margin.Left = 0;
sec1.PageInfo.Margin.Right = 0;
//Create an array containing the (X,Y) values of 4 control points
//required to position a curve
float[] posArr = new float[] { 0, 400, sec1.PageInfo.PageWidth, 400 };
// create a line with coordinates defined in array
Aspose.Pdf.Generator.Line line1 = new Line(posArr);
//Create a graph object in the section with Width=100 and Height=400
Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(sec1, sec1.PageInfo.PageWidth, sec1.PageInfo.PageHeight);
//Add Line shape into the shapes collection of the graph
//Add the graph object to the paragraphs collection of the section
//Save the Pdf

For your reference, I have also attached the resultant PDF that I have generated with Aspose.Pdf for .NET 6.3.0. I would also suggest you to please visit the following link for more information on Working with Graphs