Java生成pdf中的表格
来源:互联网 发布:自治区有什么好处知乎 编辑:程序博客网 时间:2024/05/16 01:00
package cn.gei.test;
import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class TestPDFForTable {
public static void main(String[] args) {
try {
//以A4的格式打印
Document document = new Document(PageSize.A4, 71.4f, 71.4f, 71.4f,
71.4f);
//设置输出的位置及文件名
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("c://TestPDFForTable.pdf"));
document.open();
//设置字体
BaseFont bfChinese = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 普通文字字体
Font titleFont = new Font(bfChinese, 12, Font.BOLD);
Font contentFont = new Font(bfChinese, 12);
PdfPCell cell = null;
PdfPTable table = new PdfPTable(new float[] { 20.9f, 79.1f });// 建立一个pdf表格
table.setTotalWidth(380);// 设置表格的宽度
table.setLockedWidth(true);// 设置表格的宽度固定
cell = new PdfPCell(new Paragraph("标题一", titleFont));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setRowspan(2);
table.addCell(cell);
//一下连个单元格在页面显示是一个单元格,其实使用了一个小技巧,将表格的border的宽度设为0。
Chunk chunk1 = new Chunk("内容长度可变", contentFont);
Phrase phrase1 = new Phrase(chunk1);
cell = new PdfPCell(new Paragraph(phrase1));
cell.setFixedHeight(155.0f);
cell.setBorderColorBottom(Color.red);
cell.setBorderWidthBottom(0f);
table.addCell(cell);
cell = new PdfPCell(
new Paragraph(
"固定的内容,名字,时间等等",
contentFont));
cell.setBorderWidthTop(0.01f);
cell.setBorderColorTop(Color.white);
cell.setBorderWidthBottom(0);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("标题二", titleFont));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//合并行
cell.setRowspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("内容二 ", contentFont));
cell.setFixedHeight(115.0f);
cell.setColspan(2);
table.addCell(cell);
cell = new PdfPCell(
new Paragraph(
"^^^^^^^^^^^^^^^",
titleFont));
table.addCell(cell);
cell = new PdfPCell(
new Paragraph(
">>>>>>>>>>>>>>",
titleFont));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("标题三", titleFont));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("内容四", contentFont));
cell.setFixedHeight(115.0f);
table.addCell(cell);
document.add(table);
document.close();
} catch (Exception e2) {
System.out.println(e2.getMessage());
}
}
}
- Java生成pdf中的表格
- Java iText 生成PDF表格
- JAVA 生成一个表格的 PDF文件
- java生成pdf文件包含表格
- java 如何在pdf中生成表格
- C#生成PDF表格
- 表格生成pdf
- Java生成PDF文档(表格、列表、添加图片等)
- Java iText 动态 生成 PDF 文档表格中文问题
- java代码生成PDF文件-表格和图片
- java在pdf中生成表格的方法
- java代码生成PDF文件-表格和图片
- java中生成pdf,插入图片,页眉、页脚、表格
- 使用 iTextSharp 生成 PDF 表格
- Java导出pdf表格
- java动态生成pdf含表格table和 合并两个pdf文件功能
- JAVA PDFBOX 读取PDF表格
- java 解析PDF 含表格
- c++容器无关迭代器
- 一念之间,我想改变
- oracle死锁 怎样杀死死锁!
- 关键表中数据备份防丢失的一个方法
- Unicode转换中文问题
- Java生成pdf中的表格
- Oracle 的树形递归查询
- linux下mysql命令
- 诚信开往春天的铁路
- json.lib下载地址
- 创建和使用HashTable
- sql
- Visual Studio 2010即将全球发布,或永久免费
- 生命是一种长期而持续的累积过程