删除 table iText java 的左右边距
Remove Margin Left and Right of a table iText java
我对 table 左右的 固定 边距有疑问。
我想删除那个边距并使用所有 sheet 没有边距或填充。我该怎么办?
我刚试过这个但对我不起作用:
cell.setPaddingLeft(0);
cell.setBorderWidthLeft(0);
cell.setLeft(0);
这对我有用,但是单元格的边框,不要跟随文本
(看底部的table)
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);
这就是我想要的。
默认情况下,由 PdfPTable
对象绘制的 table 仅填充页面内容区域宽度的 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)
以避免那些额外的边距。
此外,添加到 Document
的 PdfPTable
实例遵守文档边距值。要使用(几乎)整个页面作为 table 填充的页面内容区域,您必须使用带有 5 个参数的构造函数
将文档页边距减少到(几乎)0
/**
* 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)
或setter
/**
* Sets the margins.
*
* @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
* @return a <CODE>boolean</CODE>
*/
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
我对 table 左右的 固定 边距有疑问。
我想删除那个边距并使用所有 sheet 没有边距或填充。我该怎么办?
我刚试过这个但对我不起作用:
cell.setPaddingLeft(0);
cell.setBorderWidthLeft(0);
cell.setLeft(0);
这对我有用,但是单元格的边框,不要跟随文本 (看底部的table)
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);
这就是我想要的。
默认情况下,由 PdfPTable
对象绘制的 table 仅填充页面内容区域宽度的 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)
以避免那些额外的边距。
此外,添加到 Document
的 PdfPTable
实例遵守文档边距值。要使用(几乎)整个页面作为 table 填充的页面内容区域,您必须使用带有 5 个参数的构造函数
/**
* 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)
或setter
/**
* Sets the margins.
*
* @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
* @return a <CODE>boolean</CODE>
*/
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)