`
reymont
  • 浏览: 525993 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

itext设置默认NO_BORDER表格

    博客分类:
  • PDF
阅读更多

读到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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 大小: 5.9 KB
  • 大小: 9.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics