删除表格iText java左右边距

时间:2016-03-16 09:43:15

标签: itext

我在表的左右两侧有固定边距的问题。我正在使用Struts2开展一个项目。

enter image description here

我想删除该边距并使用没有边距或填充的所有工作表。我该怎么做?

我刚试过这个,但对我不起作用:

cell.setPaddingLeft(0);
cell.setBorderWidthLeft(0);
cell.setLeft(0);

这对我有用,但是单元格的边框不遵循文字 (看看底部的表格)

cell.setPaddingLeft(-50);

这是我的代码的一部分:

Font fontStandard = FontFactory.getFont("Arial", 8);
int w[] = { 50, 50 };
PdfPTable tableInner = new PdfPTable(5);
tableInner.setWidths(w);

cell = new PdfPCell(new Phrase("PADDING -50", fontStandard));
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
/******/
//cell.setPaddingLeft(0);
//cell.setBorderWidthLeft(0); 
//cell.setLeft(0); 
cell.setPaddingLeft(-50);
/******/
tableInner.addCell(cell);
document.add(tableInner);

这就是我想要的。 enter image description here

1 个答案:

答案 0 :(得分:7)

默认情况下,PdfPTable对象绘制的表仅填充页面内容区域宽度的80%。您可以使用PdfPTable方法

更改此比率
/**
 * Sets the width percentage that the table will occupy in the page.
 *
 * @param widthPercentage the width percentage that the table will occupy in
 * the page
 */
public void setWidthPercentage(final float widthPercentage)

以避免这些额外的利润。

此外,添加到PdfPTable的{​​{1}}实例会尊重文档边距值。要使用(几乎)整个页面作为要填充的表的页面内容区域,您必须使用带有5个参数的构造函数将文档边距减少到(接近)0

Document

或者二传手

/**
 * Constructs a new <CODE>Document</CODE>-object.
 *
 * @param pageSize the pageSize
 * @param marginLeft the margin on the left
 * @param marginRight the margin on the right
 * @param marginTop the margin on the top
 * @param marginBottom the margin on the bottom
 */
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
相关问题