Free Support Forum -

Draw a horizontal line which spans more than one column


I have a table with two rows. Each row has three columns.

In the second row I wanted to draw a line which spans 3 columns.

I know by specifying co-ordinates we can draw a line. But it's difficult to specify the coordinates in my case. Can we depend on columns span attribute to draw?

If posible can you please provide a sample program?



Hi Mamatha,

Thanks for using our products.

In order to accomplish your requirement, you may try adding watermark containing line object to your PDF document. The paragraph elements such as Text, Attachment, Graph etc are added in Top to Bottom flow layout and once the table is added to paragraphs collection of section element, you might not be able to add graph object on top of it. If you try to add graph object, it will be added after the table object. Besides this, if you try to add the graph object to paragraphs collection of table cell, it will only be displayed in a single cell. Until or unless the second row spans three table cells, it will not be displayed in three cells.

In current circumstances, the only viable solution is to add watermark object and set its width equal to table width and the watermark will be placed on top of table. Please take a look over following code snippet which explains the above specified scenario. For your reference, I have also attached the resultant PDF that I have generated using Aspose.Pdf for Java 3.0.1.

// create watermark object
aspose.pdf.FloatingBox watermark = new aspose.pdf.FloatingBox(table.getWidth(),2);
// create graph object and set its width equal to table width
Graph graph1 = new Graph(table.getWidth(),30);
// add graph object to paragraphs collection of watermark
// specify the coordinates for line object. width is equal to table width
float[] posArr = new float[]{table.getLeft(),0,table.getWidth(),0};
// create line object
Line l1= new Line(graph1,posArr);
// set line width information for line
//set the color information for line
l1.getGraphInfo().setColor(new Color(“Red”));
// add line to shapes collection of graph object

// add watermark to watermarks collection of PDF