我们使用的是iText PDFPTable。我们面临的问题是因为下面这行代码:
table.setHeaderRows(headerRows);这段代码在本地环境(驻留在windows中)下运行良好,但在dev server (驻留在Unix中)中不起作用,对齐混乱。我们无法弄清楚问题是什么,因为在这两种情况下都使用了IE。有人能回答一下为什么在dev server中会出现对齐问题吗?正在添加更多代码...创建标准表的方法:
public PdfPTable createStandardTable(int columnCount, int headerRows) {
zebraTable = true;
horizontalBorders = false;
PdfPTableEvent tableEvent = new PdfPTableEvent()
{
// begin (another) anonymous inner class extends PdfPTableEvent
@Override
public void tableLayout(PdfPTable table, float[][] width, float[] height,
int headerRows, int rowStart, PdfContentByte[] canvas) {
// code provided by Bruno Lowagie, author of iText, via StackOverflow.
float widths[] = width[0];
float x1 = widths[0];
float x2 = widths[widths.length - 1];
float y = height[height.length - 1];
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
cb.moveTo(x1, y);
cb.lineTo(x2, y);
cb.setColorStroke(TABLE_BORDER_COLOR);
cb.stroke();
}
// end anonymous inner class extends PdfPTableEvent
};
PdfPTable table = tableCreationHelper(columnCount, headerRows);
table.setTableEvent(tableEvent);
return table;
}私有帮助器方法
private PdfPTable tableCreationHelper(int columnCount, int headerRows) {
PdfPTable table = new PdfPTable(columnCount);
table.setSpacingBefore(TABLE_SPACING);
table.setSpacingAfter(TABLE_SPACING);
table.setWidthPercentage(TABLE_WIDTH_PERCENT);
table.setHeaderRows(headerRows);
return table;
}如果您需要更多信息,请让我知道
谢谢你,巴布。
发布于 2017-02-17 05:11:54
我发现了问题所在。开发服务器的iText版本为5.5.0,其中as本地配置为5.5.2。iText 5.5.0的setHeadersRow函数搞乱了对齐。
https://stackoverflow.com/questions/42074726
复制相似问题