去年写了对itext封装,主要是向模板写数据,而在我们的项目中不是所有的表格都是用模板的,有些表格是动态的复杂的,有些是嵌套的,需要动态去生成表格及文档。
在这一部分中对生成表格进行了封装。
如:
根据行列生成表格:
/**************************************************************************?/
/**
* 根据行列数生成指定行列的空表格
* @param rows 行数
* @param cols 列数
* @return
*/
public PdfPTable createTable(int rows, int cols) {
PdfPTable table = new PdfPTable(cols);
for (int i = 0; i < rows * cols; i++) {
PdfPCell cell;
cell = new PdfPCell();
cell.setFixedHeight(rowheight);
table.addCell(cell);
}
table.setSpacingAfter(margin);
table.setSpacingBefore(margin);
return table;
}
如根据行列生成表格:根据定制表格对象生成表格
/**
* 根据指定单元格内容,生成表格,
* @param rows
* @param cols
* @param element 定制的表格对象
* @param db 数据对象,表格中存储的数据对象
* @return
*/
public PdfPTable createFreeTable(int rows, int cols, ElementTable et,DataBean db) {
float[] colwidths = this.tp.getColwidths();
float[] rowheights = this.tp.getRowheights();
PdfPTable table = new PdfPTable(colwidths);
table.setWidthPercentage(100f);
Map<String, CellProperties> element = this
.readElementTalbe(et, this.tp);
int pan = 0;
ArrayList<String> hascell = new ArrayList<String>();
float tmprowheight = rowheight;
for (int i = 0; i < rows; i++) {
if (rowheights != null && i <= rowheights.length) {
tmprowheight = rowheights[i];
}
for (int j = 0; j < cols; j++) {
String key = i + "*" + j;
if (hascell.contains(key))
continue;
PdfPCell cell;
if (element.containsKey(key)) {
CellProperties e = element.get(key);
cell = this.getPdfPCell(e,db);
//cell.setNoWrap(false);
int type = e.getType();
pan = e.getNum();
// this.handlePdfPcell(cell, e);
if (type == PConstant.rowspan) {
cell.setRowspan(pan);
for (int k = 1; k < pan; k++) {
int tmprow;
int tmpcol;
tmprow = i + k;
tmpcol = j;
hascell.add(tmprow + "*" + tmpcol);
}
} else if (type == PConstant.colspan) {
cell.setColspan(pan);
for (int k = 1; k < pan; k++) {
int tmprow;
int tmpcol;
tmprow = i;
tmpcol = j + k;
hascell.add(tmprow + "*" + tmpcol);
}
}
} else
cell = new PdfPCell();
// 最小高度
cell.setMinimumHeight(rowheight);
cell.setFixedHeight(tmprowheight);
table.addCell(cell);
}
}
return table;
}
其它的不在一一添加,附上所有代码及测试方法。
附件于2011年7月份完成,需要iText-2.1.7.jar及iTextAsian.jar的支撑。
分享到:
相关推荐
itext 生成pdf的中文帮助文档,具体有:图片、块(下划线/删除线、上标/下标)、短句、段落等。
itext2.17
iText核心包,iTextAsian_1.5.2支持中文jar包
iTextAsian_1.5.2iTextAsian_1.5.2iTextAsian_1.5.2
iText 是一个开源的PDF文件操作类库,它可以动态生成PDF文档以及对PDF文件进行编辑更改,比如:从XML文件或数据库生成动态PDF文档、添加/更改书签、页码、添加数字签名、页面排版操作等等。功能非常强大。
常用报表操作,itext_make_pdf,itext_make_word,jexcel_make_excel,poi_make_excel,pdf,Word,excel
IText PDF开发工具说明文档,使用很方便。
iText7 原生方法制作带斜线表格
itext 生成pdf 目录,itext 生成pdf 目录,itext 生成pdf 目录
iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。 iText的安装非常方便,下载iText.jar文件后,...
iText是一个JAVA中快速制作PDF文件的类库,如果你想用JAVA制作PDF文档,这个源码包可不要错过哟。
用iText生成比较简单的表格形式Word
NULL 博文链接:https://x125858805.iteye.com/blog/2239773
itext-1.4.8
java 使用iText生成word文档,包中带有源码与所用jar包,生成文档格式标准。可分页,可带页眉,可生成表格、图片和文字等word元素内容,文字带字号,字体,颜色等。
itext应用包
iText 实现根据pdf模板生成pdf并导入数据.....iText-5.0.6.jar....附字体jar包 很久很久之前写的了 代码见: https://github.com/thisisthis/noh-doc
一段经典的处理iText打印pdf表格代码。
The iText 7 Core/Community release contains: kernel-x.y.z.jar: low-level functionality io-x.y.z.jar: low-level functionality layout-x.y.z.jar: high-level functionality forms-x.y.z.jar: AcroForms pdfa-...