ITextPdfPTable表格单元的居中显示

ITextPdfPTable表格单元的居中显⽰
昨晚寻了⽹上很多关于IText表格居中问题,他们其中的有些代码我即使复制上去⽣成的doc表格的⽂字都是不居中的,后来我⾃⼰出了⼀种居中⽅式:
为PdfPCell对象添加paragraph对象,并将该paragraph设置为居中:莲子脱皮机
    PdfPCell cell1 = new PdfPCell();
Paragraph para = new Paragraph("该单元居中");
//设置该段落为居中显⽰
para.setAlignment(1);
cell1.setPhrase(para);
便携式高压氧舱table.addCell(cell1);
代码亲测⽆误,全部代码如下:
import *;
import pdf.PdfPCell;
import pdf.PdfPTable;
import tf.RtfWriter2;
import java.io.FileOutputStream;
/**
智能一体机
* PdfPTable的使⽤⽅法,表格居中问题
* User: HYY
工业氯化钙
* Date: 13-8-1
* Time: 下午9:54
* To change this template use File | Settings | File Templates.
*/
public class PdfpTableTest {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// 创建word⽂档,并设置纸张的⼤⼩
Document document = new Document(PageSize.A4);
//设置存放位置
document.open();
//⽣成三列表格
PdfPTable table = new PdfPTable(3);
//设置表格具体宽度
table.setTotalWidth(90);
//设置每⼀列所占的长度
table.setWidths(new float[]{50f, 15f, 25f});
PdfPCell cell1 = new PdfPCell();
Paragraph para = new Paragraph("该单元居中");
//设置该段落为居中显⽰
para.setAlignment(1);ccyv2
cell1.setPhrase(para);
table.addCell(cell1);
table.addCell(new PdfPCell(new Phrase("無幽之路IText教程")));lanm
table.addCell(new PdfPCell(new Phrase("無幽之路IText教程")));
document.add(table);
document.close();
}
}

本文发布于:2024-09-22 01:28:58,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/277471.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:居中   设置   表格   代码   对象   莲子
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议