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

Free Support Forum - aspose.com

Cell Padding issue

Hi support,

The issue form this topic : Cell Padding Displaces Border , still persists. Please mention if the problem shall be solved, or if there is another solution than setting similar cell padding values for every cell within the column that has a cell with custom padding values.
Even with the workaround, the table is left indented, and didn’t found any relation between the left indent value and the cell padding values.
You can check the following code and the attached output to note my observations.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Table that has paddings on the 3rd cell");
builder.startTable();
builder.getRowFormat().setCellSpacing(2);
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2); 
builder.write("aaa"); 
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.write("aaa");
builder.endRow();

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getCellFormat().setRightPadding(30);
builder.getCellFormat().setLeftPadding(70);
builder.write("bb");

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.write("bb");

builder.endRow();
builder.endTable();

builder.writeln("Table that has paddings on first column cells");
builder.startTable();

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getCellFormat().setRightPadding(30);
builder.getCellFormat().setLeftPadding(70);
builder.write("aaa");

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.write("aaa");
builder.endRow();

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getCellFormat().setRightPadding(30);
builder.getCellFormat().setLeftPadding(70);
builder.write("bb");

builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.write("bb");

builder.endRow();
builder.endTable();

doc.save("C:\\Temp\\docCellPaddings.doc");

Thanks,
Milan

Hi
Thanks for your inquiry. The workarounds described in the forum thread you pointed works fine in your case. I think the better way is using ParagraphFormat.LeftIndent and ParagraphFormat.RightIndent instead cell padding. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Table that has paddings on the 3rd cell");
builder.startTable();
builder.getRowFormat().setCellSpacing(2);
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(0);
builder.getParagraphFormat().setRightIndent(0);
builder.write("aaa");
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(0);
builder.getParagraphFormat().setRightIndent(0);
builder.write("aaa");
builder.endRow();
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(70);
builder.getParagraphFormat().setRightIndent(30);
builder.write("bb");
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(0);
builder.getParagraphFormat().setRightIndent(0);
builder.write("bb");
builder.endRow();
builder.endTable();
builder.writeln("Table that has paddings on first column cells");
builder.startTable();
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(70);
builder.getParagraphFormat().setRightIndent(30);
builder.write("aaa");
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(0);
builder.getParagraphFormat().setRightIndent(0);
builder.write("aaa");
builder.endRow();
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(70);
builder.getParagraphFormat().setRightIndent(30);
builder.write("bb");
builder.insertCell();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setLineWidth(2);
builder.getParagraphFormat().setLeftIndent(0);
builder.getParagraphFormat().setRightIndent(0);
builder.write("bb");
builder.endRow();
builder.endTable();
doc.save("C:\\Temp\\out.doc");

I highlighted my changes.
Hope this helps.
Best regards.