Table Cell border and styling


Hi ,

I have following questions regarding table cell styling.
  • I have a table with 2 columns and I have provided cell border to every cell by creating BorderInfo object, the problem is for one part of the border the 1st cell right border and 2nd cell left is not overlapping. I need them to overlap. how can I achieve this ?
I tried following set of code still the overlapping wont happen

private static Table getTable1( ) {
Table table1 = new Table();
//Add the table in paragraphs collection of the desired section
//Set with column widths of the table
table1.setColumnWidths("50 50 50");

table1.setRepeatingRowsCount(1);
//Create rows in the table and then cells in the rows
Row row1 = table1.getRows().add();
// Set border for row object
row1.setDefaultCellBorder(new BorderInfo(
BorderSide.Left | BorderSide.Top| BorderSide.Bottom | BorderSide.Right, 1.25F, Color.getBlack()));
// Add columns in first row object
row1.getCells().add("col1");
row1.getCells().add("col2");
row1.getCells().add("col3");
table1.setRepeatingRowsCount( 1 );
// Create 100 rows with three columns each
for (int i = 0; i <= 100; i++)
{
Row row2 = table1.getRows().add();
row2.setDefaultCellBorder(new BorderInfo(
BorderSide.All , 2F, Color.getBlue()));
row2.getCells().add("ITEM1");
row2.getCells().add("ITEM2");
row2.getCells().add("ITEM3");
}
return table1;
}

Please state a way through which I can achieve overlapping.

  • Can I provide border style to cells border like dashed or dotted ?
  • I want apply image as cell's background how do I achieve this ?
  • How do I provide color gradient to cell's background ?

I am using Aspose 11 with com.aspose.pdf classes

mayekars91:
I have a table with 2 columns and I have provided cell border to every cell by creating BorderInfo object, the problem is for one part of the border the 1st cell right border and 2nd cell left is not overlapping. I need them to overlap. how can I achieve this ?
Hi Saurabh,

Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 11.2.0 and I am unable to notice any issue. As per my observations, the borders are properly overlapping. For your reference, I have also attached the output generated over my end.
mayekars91:
  • Can I provide border style to cells border like dashed or dotted ?
I am afraid this feature is currently not supported. For the sake of correction, I have logged this requirement as PDFNEWJAVA-35549 in our issue tracking system.
mayekars91:
  • I want apply image as cell’s background how do I achieve this ?
Please try using following code snippet.
[Java]

row1.getCells().add(“col3”);<o:p></o:p>

row1.getCells().get_Item(2).setBackgroundImageFile(“c:/pdftest/logoSpin.png”);

mayekars91:
  • How do I provide color gradient to cell’s background ?
Currently you can set solid color for table cell and I afraid setting a gradient color is currently not supported. For the sake of implementation, I have logged this requirement as PDFNEWJAVA-35550 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi,


The PDF that you attached also does not have the borders overlapped.
I am talking about the black or the blue thick border between the two cells.

I want to merge the right side border of left cell and left side border of the second cell.

The attached PDF also has the problem that I want to resolve.

mayekars91:
  • Can I provide border style to cells border like dashed or dotted ?
Hi Saurabh,

Thanks for your patience.

We have further looked into this requirement and in order to accomplish this feature, please try using following code snippet.

[Java]

com.aspose.pdf.Document doc = new
com.aspose.pdf.Document();<o:p></o:p>

doc.getPages().add();

Table table1 = new Table();

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

//Set with column widths of the table

table1.setColumnWidths("50 50 50");

table1.setRepeatingRowsCount(1);

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

com.aspose.pdf.Row row1 = table1.getRows().add();

// Set border for row object

row1.setDefaultCellBorder(new BorderInfo(BorderSide.Left | BorderSide.Top | BorderSide.Bottom | BorderSide.Right, 1.25F,

com.aspose.pdf.Color.getBlack()));

// Add columns in first row object

row1.getCells().add("col1");

row1.getCells().add("col2");

row1.getCells().add("col3");

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile("c:/pdftest/logoSpin.jpg");

row1.getCells().get_Item(2).getParagraphs().add(image);

table1.setRepeatingRowsCount(1);

BorderInfo borderInfo = new com.aspose.pdf.BorderInfo();

GraphInfo graphInfo = new GraphInfo();

graphInfo.setColor(com.aspose.pdf.Color.getBlue());

graphInfo.setLineWidth(2f);

graphInfo.setDashArray(new int[] { 1 });

graphInfo.setDashPhase(1);

borderInfo.setBottom(graphInfo);

borderInfo.setLeft(graphInfo);

borderInfo.setRight(graphInfo);

table1.setDefaultCellBorder(borderInfo);

// Create 100 rows with three columns each

for (int i = 0; i <= 100; i++) {

com.aspose.pdf.Row row2 = table1.getRows().add();

row2.getCells().add("ITEM1");

row2.getCells().add("ITEM2");

row2.getCells().add("ITEM3");

}

doc.getPages().get_Item(1).getParagraphs().add(table1);

doc.save(“c:/pdftest/TableBorderIssue.pdf”);


And in order to have dashed border, please try using

graphInfo.setDashArray(new int[] { 3 });
graphInfo.setDashPhase(1);
mayekars91:
Hi,

The PDF that you attached also does not have the borders overlapped.
I am talking about the black or the blue thick border between the two cells.

I want to merge the right side border of left cell and left side border of the second cell.

The attached PDF also has the problem that I want to resolve.
Hi Saurabh,

Can you please share some image file which can help us in understanding your requirements, as when I am viewing the PDF file, I can see right side border of first cell is merged with left side border of second cell. Please take a look over attached image file.

Hi,


The image that you attached is what I want to point out.
Sorry if I am stating my requirements wrong.

But by merge I mean I want to overlap the border.

The thick border that you pointed out is what I want to avoid.

I want to overlap the right side border of left cell and left side border of the second cell.

Hope I have stated my requirements correctly now.

Hi Saurabh,


Thanks for sharing the details.

As per my understanding, you need to create two border lines parallel to each other. If so is the case, then I am afraid this feature is currently not supported. But in case you need to reduce the border thickness, you may consider reducing value in BorderInfo(…) object.

row1.setDefaultCellBorder(new BorderInfo(BorderSide.Left | BorderSide.Top | BorderSide.Bottom | BorderSide.Right, .5F, com.aspose.pdf.Color.getBlack()));

In case I a still unable to understand your requirement, please share some image file, so that we can further look into this scenario.

Hi,


Thanks for the reply.
Your latest understanding is correct.

But,

The solution that you offered me I think would not help.
As I want to avoid the thick border in between cell, even if I provide 0.5F width then sides of the table will have 0.5 width border and in between it will have 1 width. Hence it will look thick.

So can you provide me another solution ?
It would be better if I don’t have to do it manually can you fix it in your next release ? or can you please provide some easy solution which does not involve any calculation ?

Hi Saurabh,


Thanks for sharing the details.

Please allow me to rephrase what I have understood from above explanation and earlier discussion in forum thread. The left and right border of second cell in first row is appearing thick as compared to other borders on same row and its because right border of first cell is appearing besides left border of second cell, so they both give an appearance of thick border. Instead a cumulative and single border should be displayed. For the sake of correction, I have logged this problem as PDFNEWJAVA-35600 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi,


Yes your understanding is correct.
That is exactly what I want to achieve.


Hi Saurabh,


Thanks for the acknowledgement.

The product team will start investigating the earlier reported issues as per their development schedule and as soon as we have some definite updates regarding their resolution, we will let you know. We are sorry for your inconvenience.

Hi Saurabh,


Thanks for your patience. We have investigated the requirement(PDFNEWJAVA-35550) and would like to suggest you to create a gradient image by using java.awt and then add this image as a background via method cell.setBackgroundImageFile(…). Please, see the full code snippet below, it will help you to accomplish the task.

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();<o:p></o:p>

doc.getPages().add();<o:p></o:p>

Table table1 = new Table();<o:p></o:p>

table1.setColumnWidths(“50 50
50”
);<o:p></o:p>

table1.setRepeatingRowsCount(1);<o:p></o:p>

com.aspose.pdf.Row row1 =
table1.getRows().add();<o:p></o:p>

row1.setDefaultCellBorder(new BorderInfo(<o:p></o:p>

BorderSide.Left | BorderSide.Top | BorderSide.Bottom | BorderSide.Right, 1.25F,
com.aspose.pdf.Color.getBlack()));<o:p></o:p>

row1.getCells().add(“col1”);<o:p></o:p>

row1.getCells().add(“col2”);<o:p></o:p>

row1.getCells().add(“col3”);<o:p></o:p>

table1.setRepeatingRowsCount(1);<o:p></o:p>

BufferedImage bufferedImage = createGradientMask(100, 100, 1);<o:p></o:p>

ImageIO.write(bufferedImage, “jpg”, new File(“c:/pdftest/temp_bk.jpg”));<o:p></o:p>


<o:p></o:p>

// Create 100 rows with three
columns each
<o:p></o:p>

for (int i = 0; i <= 100;
i++) {<o:p></o:p>


com.aspose.pdf.Row row2 = table1.getRows().add();<o:p></o:p>


row2.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(BorderSide.All, 2F,
com.aspose.pdf.Color.getBlue()));<o:p></o:p>


row2.getCells().add(“ITEM1”);<o:p></o:p>


row2.getCells().add(“ITEM2”);<o:p></o:p>

<o:p></o:p>


Cell cell = row2.getCells().add(“ITEM3”); <o:p></o:p>


cell.setBackgroundImageFile(“c:/pdftest/temp_bk.jpg”);<o:p></o:p>

}<o:p></o:p>

doc.getPages().get_Item(1).getParagraphs().add(table1);<o:p></o:p>

doc.save(“c:/pdftest/TableBorderIssue.pdf”);<o:p></o:p>

new File(“c:/pdftest/temp_bk.jpg”).delete();<o:p></o:p>

…<o:p></o:p>

public static BufferedImage
createGradientMask(int width, int height, int orientation) {<o:p></o:p>

BufferedImage gradient = new BufferedImage(width,
height, BufferedImage.TYPE_INT_ARGB);<o:p></o:p>

Graphics2D g = gradient.createGraphics();<o:p></o:p>

GradientPaint paint = new GradientPaint(0.0f,
0.0f, new java.awt.Color(1.0f,
1.0f, 1.0f, 1.0f),<o:p></o:p>

orientation == 0 ? width : 0.0f,<o:p></o:p>

orientation == 1 ? height : 0.0f,<o:p></o:p>

new java.awt.Color(1.0f, 1.0f, 1.0f, 0.0f));<o:p></o:p>

g.setPaint(paint);<o:p></o:p>

g.fill(new
Rectangle2D.Double(0, 0, width, height));<o:p></o:p>

g.dispose();<o:p></o:p>

gradient.flush();<o:p></o:p>

return gradient;<o:p></o:p>

}


Best Regards,

2 posts were split to a new topic: Add custom table in document