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

Free Support Forum - aspose.com

How to draw line in Aspose table

I am using Aspoe PDf to display data. To show details about various categories, I am using data table.
After data corresponding to each category ,, I need to draw a line, that spans the entire columns in the
data table. Is there any way to draw a line in Aspose pdf table.

Thanks,
Surya.

Hi Surya,


Thanks for your inquiry. I’m afraid I couldn’t understand your requirement properly, Can you please share your sample output and desired document here? So we will look into it and will provide you information accordingly.

Sorry for the inconvenience faced.

Best Regards,

Hi Surya,


I have gone through your requirement and as per my observations, you need to add line in table cell containing data from DataTable. If so is the case, you may consider creating a Line object and add it to Graphs collection and then add the graph object to paragraphs collection of particular table cell. Please take a look over following code snippet.

In case I am unable to understand the required, please share some further details.

[C#]

//Instntiate the Pdf object by calling
its empty constructor
<o:p></o:p>

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Create the section in the Pdf object

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

//Instantiate a table object

Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();

//Add the table in paragraphs collection of the desired section

sec1.Paragraphs.Add(tab1);

//Set with column widths of the table

tab1.ColumnWidths = "50 50 50";

//Set default cell border using BorderInfo object

tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);

//Set table border using another customized BorderInfo object

tab1.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);

//Create MarginInfo object and set its left, bottom, right and top margins

Aspose.Pdf.Generator.MarginInfo margin = new Aspose.Pdf.Generator.MarginInfo();

margin.Top = 5f;

margin.Left = 5f;

margin.Right = 5f;

margin.Bottom = 5f;

//Set the default cell padding to the MarginInfo object

tab1.DefaultCellPadding = margin;

//Create rows in the table and then cells in the rows

Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add();

row1.Cells.Add("col1");

//Create a graph object in the section with Width=100 and Height=400

Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(sec1, 100, 50);

//Create an array containing the (X,Y) values

//required position for line

float[] posArr = new float[] { 0, 100, 50, 100 };

// create line object

Line l1 = new Line(graph1, posArr);

l1.GraphInfo.Color = new Aspose.Pdf.Generator.Color("Red");

graph1.Shapes.Add(l1);

// add graph object to paragraphs collection of cell object

row1.Cells[0].Paragraphs.Add(graph1);

row1.Cells.Add("col2");

row1.Cells.Add("col3");

Aspose.Pdf.Generator.Row row2 = tab1.Rows.Add();

row2.Cells.Add("item1");

row2.Cells.Add("item2");

row2.Cells.Add("item3");

//Save the Pdf

pdf1.Save(“C:/pdftest/TableResult.pdf”);