itext设置默认NO_BORDER表格

读到itext in action第6章6.1.3,有个函数getDefaultCell(),查看该函数的API

 

 

 

PdfPCell com.lowagie.text.pdf. PdfPTable .getDefaultCell()

 

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell) .

 

那么就是说你使用new PdfPCell就有border

 

 

那再查看PdfPCell的构造函数。以PdfPCell()和PdfPCell(Phrase)为例,发现的确有默认的border。

 

 

 

参照第6章的代码PdfPTableWithoutBorders做小小的改动

 

 

/* chapter06/PdfPTableWithoutBorders.java */

package org.study.itext.table;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

/**
 * @blog http://reymont.iteye.com/
 * @author reymont.li
 * @version create time:2011-7-18 下午04:13:47
 */
public class PdfPTableWithoutBorders {

	public static void main(String[] args) {
		Document document = new Document();
		try {
			PdfWriter.getInstance(
					document,
					new FileOutputStream("resource/pdfptable_without_borders.pdf"));
			document.open();
			PdfPTable table = new PdfPTable(3);
			table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
			PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
			//cell.setColspan(3);
			table.addCell(cell);
			table.addCell(new Paragraph("header with colspan 3"));
			
			
			table.addCell("1.1");
			table.addCell("2.1");
			table.addCell("3.1");
			table.addCell("1.2");
			table.addCell("2.2");
			table.addCell("3.2");
			document.add(table);
		} catch (DocumentException de) {
			System.err.println(de.getMessage());
		} catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		}

		document.close();
	}
}
 

可得到。

请注意addCell(new PdfPCell())和addCell(new Paragraph())的区别

 

PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
table.addCell(cell);
table.addCell(new Paragraph("header with colspan 3"));
 

 

参考资料:

  • itext in action 2006版
  • itext-2.0.8

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值