接着
上一篇
文章继续说,上篇文章说到把生成的Base64格式的图片写到Pdf文档里面。至于写入到Pdf文档中其实有很多类库来操作。比如上篇提到的
spire
以及
itext
。
本篇文章以 itext 为例来讲述如何通过 itext 操作Pdf文档。
1、什么是 itext ?
用官方
github仓库
上面的介绍来讲,iText for Java代表了希望利用PDF所带来的好处的开发者的下一代SDK。iText配备了更好的文档引擎、高级和低级编程能力以及创建、编辑和增强PDF文档的能力,它几乎可以成为每个工作流程的福音。目前itext官方最新的版本是itext7。
2、如何使用 itext
2.1 引入 jar包
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.2.2</version>
<type>pom</type>
</dependency>
2.2 demo 示例
下面举几个简单的例子,例子内容包含 自定义表格、自定义单元格颜色、自定义字体、自定义字体颜色、自定义文本块、表格添加图片、写入图片、图片增加水印、添加页眉、添加页脚等。本篇文章所有示例可在github仓库查看。更多示例可参考 官方示例文档 或者官方示例demo。
2.2.1 表格
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.UnitValue;
import java.io.File;
import java.io.IOException;
* 简单的表格
* @author demain_lee
* @since 2022/12/30
public class SimpleTable {
public static final String DEST = "./target/sandbox/tables/simple_table.pdf";
* 设置字体
* 默认字体不支持中文
private static final String SIMSUN = "./itext7-demo/src/main/resources/fonts/simsun.ttf";
PdfFont simsumFont = PdfFontFactory.createFont(SIMSUN);
public SimpleTable() throws IOException {
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new SimpleTable().manipulatePdf(DEST);
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Table table = new Table(UnitValue.createPercentArray(8)).useAllAvailableWidth();
table.setFont(simsumFont);
for (int i = 0; i < 16; i++) {
table.addCell("我是测试数据");
doc.add(table);
doc.close();
2.2.2 自定义单元格颜色以及字体颜色
import com.itextpdf.kernel.colors.ColorConstants
import com.itextpdf.kernel.font.PdfFont
import com.itextpdf.kernel.font.PdfFontFactory
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.layout.Document
import com.itextpdf.layout.element.Cell
import com.itextpdf.layout.element.Paragraph
import com.itextpdf.layout.element.Table
import com.itextpdf.layout.properties.UnitValue
import java.io.File
import java.io.IOException
* 简单的表格 自定义单元格颜色以及字体颜色
* @author demain_lee
* @since 2022/12/30
public class SimpleTable2 {
public static final String DEST = "./target/sandbox/tables/simple_table2.pdf"
* 设置字体
* 默认字体不支持中文
private static final String SIMSUN = "./itext7-demo/src/main/resources/fonts/simsun.ttf"
PdfFont simsumFont = PdfFontFactory.createFont(SIMSUN)
public SimpleTable2() throws IOException {
public static void main(String[] args) throws Exception {
File file = new File(DEST)
file.getParentFile().mkdirs()
new SimpleTable2().manipulatePdf(DEST)
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest))
Document doc = new Document(pdfDoc)
Table table = new Table(UnitValue.createPercentArray(4)).useAllAvailableWidth()
Cell sn = new Cell(2, 1).setFont(simsumFont).add(new Paragraph("序号"))
sn.setBackgroundColor(ColorConstants.YELLOW)
table.addCell(sn)
Cell name = new Cell(1, 2).setFont(simsumFont).add(new Paragraph("名字"))
name.setBackgroundColor(ColorConstants.CYAN)
table.addCell(name)
Cell age = new Cell(2, 1).setFont(simsumFont).add(new Paragraph("年龄"))
age.setBackgroundColor(ColorConstants.GRAY)
table.addCell(age)
Cell surname = new Cell().setFont(simsumFont).setFontColor(ColorConstants.ORANGE).add(new Paragraph("姓氏"))
table.addCell(surname)
Cell firstname = new Cell().setFont(simsumFont).add(new Paragraph("名字"))
firstname.setBackgroundColor(ColorConstants.RED)
table.addCell(firstname)
Cell f1 = new Cell().add(new Paragraph("1"))
f1.setBackgroundColor(ColorConstants.PINK)
table.addCell(f1)
Cell f2 = new Cell().setFont(simsumFont).add(new Paragraph("张"))
f2.setBackgroundColor(ColorConstants.MAGENTA)
table.addCell(f2)
Cell f3 = new Cell().setFont(simsumFont).add(new Paragraph("三丰"))
f3.setBackgroundColor(ColorConstants.ORANGE)
table.addCell(f3)
Cell f4 = new Cell().add(new Paragraph("18"))
f4.setBackgroundColor(ColorConstants.LIGHT_GRAY)
table.addCell(f4)
doc.add(table)
doc.close()
2.2.3 单元格中添加图片
import com.itextpdf.io.image.ImageDataFactory
import com.itextpdf.kernel.font.PdfFont
import com.itextpdf.kernel.font.PdfFontFactory
import com.itextpdf.kernel.geom.Rectangle
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.layout.Canvas
import com.itextpdf.layout.Document
import com.itextpdf.layout.element.*
import com.itextpdf.layout.properties.Leading
import com.itextpdf.layout.properties.Property
import com.itextpdf.layout.properties.TextAlignment
import com.itextpdf.layout.properties.UnitValue
import com.itextpdf.layout.renderer.CellRenderer
import com.itextpdf.layout.renderer.DocumentRenderer
import com.itextpdf.layout.renderer.DrawContext
import com.itextpdf.layout.renderer.IRenderer
import java.io.File
import java.io.IOException
* 在单元格中添加图片
* @author demain_lee
* @since 2022/12/30
public class PositionContentInCell {
public static final String DEST = "./target/sandbox/tables/position_content_in_cell.pdf"
public static final String IMG = "./itext7-demo/src/main/resources/img/info.png"
* 设置字体
* 默认字体不支持中文
private static final String SIMSUN = "./itext7-demo/src/main/resources/fonts/simsun.ttf"
PdfFont simsumFont = PdfFontFactory.createFont(SIMSUN)
public PositionContentInCell() throws IOException {
public enum POSITION {
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT
public static void main(String[] args) throws Exception {
File file = new File(DEST)
file.getParentFile().mkdirs()
new PositionContentInCell().manipulatePdf(DEST)
protected void manipulatePdf(String dest) throws Exception {
// 1. 创建一个包含表格的文档:
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest))
Document doc = new Document(pdfDoc)
Table table = new Table(UnitValue.createPercentArray(2)).useAllAvailableWidth()
Cell cell1 = new Cell()
Cell cell2 = new Cell()
Cell cell3 = new Cell()
Cell cell4 = new Cell()
// 2. 在该表内,使每个单元格具有特定高度:
cell1.setHeight(50)
cell2.setHeight(50)
cell3.setHeight(50)
cell4.setHeight(50)
// 3. 每个单元格都有相同的背景图像
// 4. 在特定位置的图像前面添加文本
cell1.setNextRenderer(new ImageAndPositionRenderer(cell1, new Image(ImageDataFactory.create(IMG)),
new Text("左上").setFont(simsumFont), POSITION.TOP_LEFT))
cell2.setNextRenderer(new ImageAndPositionRenderer(cell2, new Image(ImageDataFactory.create(IMG)),
new Text("右上").setFont(simsumFont), POSITION.TOP_RIGHT))
cell3.setNextRenderer(new ImageAndPositionRenderer(cell3, new Image(ImageDataFactory.create(IMG)),
new Text("左下").setFont(simsumFont), POSITION.BOTTOM_LEFT))
cell4.setNextRenderer(new ImageAndPositionRenderer(cell4, new Image(ImageDataFactory.create(IMG)),
new Text("右下").setFont(simsumFont), POSITION.BOTTOM_RIGHT))
table.addCell(cell1)
table.addCell(cell2.setFont(simsumFont))
table.addCell(cell3)
table.addCell(cell4)
doc.add(table)
doc.close()
private static class ImageAndPositionRenderer extends CellRenderer {
private Image img
private Text content
private POSITION position
public ImageAndPositionRenderer(Cell modelElement, Image img, Text content, POSITION position) {
super(modelElement)
this.img = img
this.content = content
this.position
= position
// 如果渲染器在下一个区域溢出,iText 使用 getNextRenderer() 方法为溢出部分创建一个新的渲染器。
// 如果 getNextRenderer() 未被覆盖,则将使用默认方法,
// 因此将创建默认渲染器而不是自定义渲染器
@Override
public IRenderer getNextRenderer() {
return new ImageAndPositionRenderer((Cell) modelElement, img, content, position)
@Override
public void draw(DrawContext drawContext) {
super.draw(drawContext)
Rectangle area = getOccupiedAreaBBox()
img.scaleToFit(area.getWidth(), area.getHeight())
drawContext.getCanvas().addXObjectFittedIntoRectangle(img.getXObject(), new Rectangle(
area.getX() + (area.getWidth() - img.getImageWidth()
* (float) img.getProperty(Property.HORIZONTAL_SCALING)) / 2,
area.getY() + (area.getHeight() - img.getImageHeight()
* (float) img.getProperty(Property.VERTICAL_SCALING)) / 2,
img.getImageWidth() * (float) img.getProperty(Property.HORIZONTAL_SCALING),
img.getImageHeight() * (float) img.getProperty(Property.VERTICAL_SCALING)))
drawContext.getCanvas().stroke()
Paragraph p = new Paragraph(content)
Leading leading = p.getDefaultProperty(Property.LEADING)
UnitValue defaultFontSizeUV = new DocumentRenderer(new Document(drawContext.getDocument()))
.getPropertyAsUnitValue(Property.FONT_SIZE)
float defaultFontSize = defaultFontSizeUV.isPointValue() ? defaultFontSizeUV.getValue() : 12f
float x
float y
TextAlignment alignment
switch (position) {
case TOP_LEFT: {
x = area.getLeft() + 3
y = area.getTop() - defaultFontSize * leading.getValue()
alignment = TextAlignment.LEFT
break
case TOP_RIGHT: {
x = area.getRight() - 3
y = area.getTop() - defaultFontSize * leading.getValue()
alignment = TextAlignment.RIGHT
break
case BOTTOM_LEFT: {
x = area.getLeft() + 3
y = area.getBottom() + 3
alignment = TextAlignment.LEFT
break
case BOTTOM_RIGHT: {
x = area.getRight() - 3
y = area.getBottom() + 3
alignment = TextAlignment.RIGHT
break
default: {
x = 0
y = 0
alignment = TextAlignment.CENTER
new Canvas(drawContext.getCanvas(), area).showTextAligned(p, x, y, alignment)
2.2.4 图像添加水印
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.colors.DeviceGray;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
import com.itextpdf.layout.Canvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.properties.TextAlignment;
import java.io.File;
import java.io.IOException;
* 图像添加水印
* @author demain_lee
* @since 2022/12/30
public class WatermarkedImages {
public static final String DEST = "./target/sandbox/images/watermarked_images.pdf";
public static final String IMAGE = "./itext7-demo/src/main/resources/img/bake.jpeg";
String watermarked_eg = "watermarked";
String watermarked_ch = "我是中文水印";
* 设置字体样式
private static final String SIMSUN = "./itext7-demo/src/main/resources/fonts/simsun.ttf";
* 自定义字体
static PdfFont simsumFont;
static {
try {
simsumFont = PdfFontFactory.createFont(SIMSUN);
} catch (IOException e) {
throw new RuntimeException(e);
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new WatermarkedImages().manipulatePdf(DEST);
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Image image = getWatermarkedImage(pdfDoc, new Image(ImageDataFactory.create(IMAGE)), watermarked_ch);
doc.add(image);
doc.close();
private static Image getWatermarkedImage(PdfDocument pdfDoc, Image img, String watermark) {
float width = img.getImageScaledWidth();
float height = img.getImageScaledHeight();
PdfFormXObject template = new PdfFormXObject(new Rectangle(width, height));
new Canvas(template, pdfDoc)
.add(img)
.setFont(simsumFont)
.setFontSize(30)
.setFontColor(DeviceGray.WHITE)
.showTextAligned(watermark, width / 2, height / 2, TextAlignment.CENTER, (float) Math.PI / 6)
.close();
return new Image(template);
2.2.5 页眉、页脚
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
import com.itextpdf.layout.properties.TextAlignment;
import com.itextpdf.layout.properties.VerticalAlignment;
import java.io.File;
import java.io.IOException;
* 页眉、页脚
* @author demain_lee
* @since 2022/12/30
public class StampHeader {
public static final String DEST = "./target/sandbox/stamper/stamp_header.pdf";
public static final String SRC = "./target/sandbox/images/watermarked_images.pdf";
* 设置字体样式
private static final String SIMSUN = "./itext7-demo/src/main/resources/fonts/simsun.ttf";
* 自定义字体
static PdfFont simsumFont;
static {
try {
simsumFont = PdfFontFactory.createFont(SIMSUN);
} catch (IOException e) {
throw new RuntimeException(e);
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new StampHeader().manipulatePdf(DEST);
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Paragraph header = new Paragraph(new Text("我是header")
.setFont(simsumFont)
.setFontSize(8)
.setFontColor(ColorConstants.GRAY))
.setHeight(15)
.setBorderBottom(new SolidBorder(ColorConstants.GRAY, 0.1f));
Paragraph footer = new Paragraph(new Text("我是footer")
.setFont(simsumFont)
.setFontSize(8)
.setFontColor(ColorConstants.GRAY))
.setHeight(15)
.setBorderBottom(new SolidBorder(ColorConstants.GRAY, 0.1f));
for (int i = 1; i <= pdfDoc.getNumberOfPages(); i++) {
Rectangle pageSize = pdfDoc.getPage(i).getPageSize();
float x = pageSize.getWidth() / 2;
float y = pageSize.getTop() - 20;
float fy = pageSize.getBottom() + 20;
doc.showTextAligned(header, x, y, i, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
doc.showTextAligned(footer, x, fy, i, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
doc.close();
3、实际项目使用
上面介绍了一些使用的示例,下面以实际项目为例,介绍下实际项目中如何运用 itext 生成pdf文档。
3.1 实际效果图
3.2 代码
下方代码有好些需要优化的地方,这里只是以示例的方式来介绍 itext的用法,在实际项目中公共代码最好单独抽取出来进行封装,提高代码的复用性。
CreatePDF.java
import com.itextpdf.kernel.geom.PageSize
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.layout.Document
import com.itextpdf.layout.element.AreaBreak
import com.itextpdf.layout.properties.AreaBreakType
import java.io.IOException
public class CreatePDF {
public static void main(String[] args) throws IOException {
String pdfName = "invoice.pdf"
PdfWriter pdfWriter = new PdfWriter(pdfName)
PdfDocument pdfDocument = new PdfDocument(pdfWriter)
pdfDocument.addNewPage()
Document document = new Document(pdfDocument)
// 设置页面大小
pdfDocument.setDefaultPageSize(PageSize.A4)
Invoice invoice = new Invoice()
document.add(invoice.titleTable())
// 在表之间添加空格
// document.add(new Paragraph("\n"))
// 个人信息
document.add(invoice.customerInfoTable())
// xxxx
document.add(invoice.physicalQualityTable())
// xxxx
document.add(invoice.psychologicalQualityTable())
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE))
// xxxx
document.add(invoice.attackAttributesTable())
// xxx
document.add(invoice.defensiveAttributesTable())
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE))
// xxxx
document.add(invoice.willQualityTable())
// xxxx
document.add(invoice.adviceTable())
document.close()
System.out.println("PDF 已经创建 !!!")
Invoice.java
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.layout.Style;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.*;
import com.itextpdf.layout.properties.TextAlignment;
import com.itextpdf.layout.properties.VerticalAlignment;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Base64;
public class Invoice {
float col = 280f;
float[] headerTableColumnWidth = {col, col};
float[] customerInfoTableColumnWidth = {140, 140, 140, 140};
float[] physicalQualityTableColumnWidth = {560 / 3f, 560 / 3f, 560 / 3f};
float[] attackTableColumnWidth = {70, 35, 35, 70, 70, 35, 35, 70, 70, 70};
public static final String IMG1 = "src/main/resources/images/test2.png";
public Invoice() throws IOException {
* 默认字体
PdfFont defaultFont = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
* 设置字体样式
PdfFont simsumFont = PdfFontFactory.createFont("STSong-Light","UniGB-UCS2-H");
* 字体大小
private static final Float FONT30 = 30f;
private static final Float FONT25 = 25f;
private static final Float FONT20 = 20f;
private static final Float FONT16 = 16f;
private static final Float FONT10 = 10f;
private static final Float FONT8 = 8f;
private static final Float FONT4 = 4f;
* 线条宽度
private static final Float BORDER_WIDTH3 = 0.3f;
* 表格高度
private static final Float TABLE_HEIGHT_FIRST = 25f;
private static final Float TABLE_HEIGHT_SECOND = 22f;
private static final Float TABLE_HEIGHT_25 = 25f;
private static final Float TABLE_HEIGHT_35 = 35f;
private static final Float TABLE_HEIGHT_44 = 44f;
private static final Float TABLE_HEIGHT_450 = 415f;
* 表格上边距
private static final Float TABLE_MARGIN_TOP = 15f;
Style topLeftRightStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderLeft(new SolidBorder(BORDER_WIDTH3))
.setBorderRight(new SolidBorder(BORDER_WIDTH3));
Style topStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3));
Style topLeftStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderLeft(new SolidBorder(BORDER_WIDTH3));
Style topRightStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderRight(new SolidBorder(BORDER_WIDTH3));
Style topLeftBottomStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderLeft(new SolidBorder(BORDER_WIDTH3))
.setBorderBottom(new SolidBorder(BORDER_WIDTH3));
Style topRightBottomStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderRight(new SolidBorder(BORDER_WIDTH3))
.setBorderBottom(new SolidBorder(BORDER_WIDTH3));
Style topLeftRightBottomStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderTop(new SolidBorder(BORDER_WIDTH3))
.setBorderLeft(new SolidBorder(BORDER_WIDTH3))
.setBorderRight(new SolidBorder(BORDER_WIDTH3))
.setBorderBottom(new SolidBorder(BORDER_WIDTH3));
Style leftBottomStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderLeft(new SolidBorder(BORDER_WIDTH3))
.setBorderBottom(new SolidBorder(BORDER_WIDTH3));
Style leftRightBottomStyle = new Style()
.setBorder(Border.NO_BORDER)
.setBorderLeft(new SolidBorder(BORDER_WIDTH3))
.setBorderRight(new SolidBorder(BORDER_WIDTH3))
.setBorderBottom(new SolidBorder(BORDER_WIDTH3));
public Table titleTable() {
Table headerTable = new Table(headerTableColumnWidth);
Style headerStyle = new Style()
.setBorder(Border.NO_BORDER)
.setPadding(1f);
Text title = new Text("xxxxx报告").setFont(simsumFont);
headerTable.addCell(new Cell(0, 2).add(new Paragraph().add(title)).setBold().addStyle(headerStyle)
.setTextAlignment(TextAlignment.CENTER)
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.setMarginTop(20f)
.setMarginBottom(20f)
.setFontSize(FONT25)
return headerTable;
* xxxxx
public Table customerInfoTable() {
Table customerInfoTable = new Table(customerInfoTableColumnWidth);
String nameData = "张三";
String ageData = "xx";
String sexData = "xx";
String nationData = "xx";
String marriageStateData = "xx";
String yearOfWorkingData = "xxx年";
String workLevellData = "xxx";
String degreeData = "xxx";
String departmentData = "xxxx";
String majorData = "xxxxx";
Text cusTitle = new Text("个人信息").setFont(simsumFont);
Text name = new Text("姓名: " + nameData).setFont(simsumFont);
Text age = new Text("年龄: " + ageData).setFont(simsumFont);
Text sex = new Text("性别: " + sexData).setFont(simsumFont);
Text nation = new Text("民族: " + nationData).setFont(simsumFont);
Text marriageState = new Text("婚姻状况: " + marriageStateData).setFont(simsumFont);
Text yearOfWorking = new Text("xx: " + yearOfWorkingData).setFont(simsumFont);
Text workLevell = new Text("xx: " + workLevellData).setFont(simsumFont);
Text degree = new Text("学历: " + degreeData).setFont(simsumFont);
Text department = new Text("所属单位: " + departmentData).setFont(simsumFont);
Text major = new Text("专业: " + majorData).setFont(simsumFont);
customerInfoTable.addCell(new Cell(0, 4).setHeight(TABLE_HEIGHT_FIRST).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(cusTitle).setBold().setFontSize(FONT16)).addStyle(topLeftRightStyle)).setMarginTop(TABLE_MARGIN_TOP);
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment
(VerticalAlignment.MIDDLE).add(new Paragraph().add(name)).addStyle(topLeftStyle)).setFontSize(FONT10);
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(age)).addStyle(topStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(sex)).addStyle(topStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(nation)).addStyle(topRightStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(marriageState)).addStyle(topLeftStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(yearOfWorking)).addStyle(topStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(workLevell)).addStyle(topStyle));
customerInfoTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(degree)).addStyle(topRightStyle));
customerInfoTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(department)).addStyle(topLeftBottomStyle));
customerInfoTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(major)).addStyle(topRightBottomStyle));
return customerInfoTable;
* xxxxxxx
public Table physicalQualityTable() {
Table physicalQualityTable = new Table(physicalQualityTableColumnWidth);
String bmiData = "23";
String longRunTimeData = "xxx";
String shortRunTimeData = "10分";
String pullUpData = "xxx";
String fiveTotalTimeData = "10分20秒";
Text phyTitle = new Text("xxxxxxxx").setFont(simsumFont);
Text bmi = new Text("xxxx: " + bmiData).setFont(simsumFont);
Text longRunTime = new Text("xxx: " + longRunTimeData).setFont(simsumFont);
Text shortRunTime = new Text("xxx: " + shortRunTimeData).setFont(simsumFont);
Text pullUp = new Text("xxxxxxx: " + pullUpData).setFont(simsumFont);
Text fiveTotalTime = new Text("xxxx: " + fiveTotalTimeData).setFont(simsumFont);
physicalQualityTable.addCell(new Cell(0, 3).setHeight(TABLE_HEIGHT_FIRST).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(phyTitle).setBold().setFontSize(FONT16)).addStyle(topLeftRightStyle)).setMarginTop(TABLE_MARGIN_TOP);
physicalQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(bmi)).addStyle(topLeftStyle)).setFontSize(FONT10);
physicalQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(longRunTime)).addStyle(topStyle));
physicalQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(shortRunTime)).addStyle(topRightStyle));
physicalQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(pullUp)).addStyle(topLeftBottomStyle));
physicalQualityTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_SECOND).setVerticalAlignment(VerticalAlignment.MIDDLE).add(new Paragraph().add(fiveTotalTime)).addStyle(topRightBottomStyle));
return physicalQualityTable;
* xxxxxx
public Table psychologicalQualityTable() throws MalformedURLException {
Table psychologicalQualityTable = new Table(customerInfoTableColumnWidth);
String bmiData = "23";
Text phyTitle = new Text("xxxxx").setFont(simsumFont);
psychologicalQualityTable.addCell(new Cell(0, 4).setHeight(TABLE_HEIGHT_FIRST).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(phyTitle).setBold().setFontSize(FONT16)).addStyle(topLeftRightStyle)).setMarginTop(TABLE_MARGIN_TOP);
Cell cell = new Cell(0, 4);
String imgUrl = "iVBORw0KGgoAAAANSUhEUgAAAyAAAAGQCAYAAABWJQQ0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAgAElEQVR4nOzdd5xcZb0/8M85c6bP9pJks5uezYb0AglEahJCUxQVbgSUeq8FuYAKykURvSJS5CfqVa/0GkBQygVCMKA0IaQT0jdlN237Tp9Tf3+siSTZ3cxzZnbaft4v8lqyu9/nPJtkzsxnniZZlmWBiIiIiIgoA+Rsd4CIiIiIiAYPBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYBhAiIiIiIsoYJdsdICKiwqHrOhobG7Ft2zZ0d3fD4/HA7XYf+njw/w/++vTnXC5XtrtPREQZwABCRERHMS0LhgGYpgXTsmCa+NdH04Jp9fwePf8BFrB8+et45ZXXEQxFYDmHArIPlqlCgg6YKiQYsCyt5/8tDaapAqYGy9RgGCoqq0chEetGRWU1qocMwYjaYRhRNwzV1dUYOnQoqqurs/3HQkREaSBZlmVluxNERJR5umFBNywYhgXD7Pmo
byte[] strToBytes2 = getStrToBytes(imgUrl);
Image image = new Image(ImageDataFactory.create(strToBytes2));
image.setAutoScale(true);
cell.add(image);
psychologicalQualityTable.addCell(cell.setHeight(TABLE_HEIGHT_450).setVerticalAlignment(VerticalAlignment.MIDDLE).addStyle(topLeftRightBottomStyle)).setFontSize(FONT10);
return psychologicalQualityTable;
* xxxxxxx
public Table attackAttributesTable() {
Table attackAttributesTable = new Table(attackTableColumnWidth);
Text attTitle = new Text("xxxxx").setFont(simsumFont);
Text attDes = new Text("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").setFont(simsumFont);
Text attTableTitle1 = new Text("xxx").setFont(simsumFont);
Text attTableTitle2 = new Text("xxx").setFont(simsumFont);
Text attTableTitle3 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle4 = new Text("xxxxx").setFont(simsumFont);
Text attTableTitle5 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle6 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle7 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle8 = new Text("xxxxx").setFont(simsumFont);
Text attTableTitle9 = new Text("xxxxx").setFont(simsumFont);
Text attTableTitle10 = new Text("xxxxx").setFont(simsumFont);
Text attTableValue1 = new Text("xxxx").setFont(simsumFont);
Text attTableValue2 = new Text("xxxxxx").setFont(simsumFont);
Text attTableValue3 = new Text("xxxx").setFont(simsumFont);
Text attTableValue4 = new Text("xxxxx").setFont(simsumFont);
Text attTableValue5 = new Text("xxx").setFont(simsumFont);
Text attTableValue6 = new Text("7").setFont(simsumFont);
Text attTableValue7 = new Text("1").setFont(simsumFont);
Text attTableValue8 = new Text("~3.5(含)").setFont(simsumFont);
Text attTableValue9 = new Text("5.5~6.5(含)").setFont(simsumFont);
Text attTableValue10 = new Text("6.5(含)").setFont(simsumFont);
attackAttributesTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(attTitle).setBold().setFontSize(FONT16)).addStyle(topLeftStyle)).setMarginTop(TABLE_MARGIN_TOP);
attackAttributesTable.addCell(new Cell(0, 8).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.BOTTOM)
.add(new Paragraph().add(attDes)).addStyle(topRightStyle)).setMarginTop(TABLE_MARGIN_TOP).setFontSize(FONT4);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle1).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle2).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle3).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle4).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle5).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle6).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle7).setBold
()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle8).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle9).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle10).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftRightBottomStyle)).setFontSize(FONT10);
for (int i = 0; i < 4; i++) {
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue1)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue2)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue3)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue4)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue5)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue6)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue7)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue8)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue9)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
attackAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue10)).setTextAlignment(TextAlignment.CENTER).addStyle(leftRightBottomStyle)).setFontSize(FONT10);
return attackAttributesTable;
* xxxxx
public Table defensiveAttributesTable() {
Table defensiveAttributesTable = new Table(attackTableColumnWidth);
Text attTitle = new Text("xxxx").setFont(simsumFont);
Text attDes = new Text("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").setFont(simsumFont);
Text attTableTitle1 = new Text("xxx").setFont(simsumFont);
Text attTableTitle2 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle3 = new Text("xxx").setFont(simsumFont);
Text attTableTitle4 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle5 = new Text("xxxxx").setFont(simsumFont);
Text attTableTitle6 = new Text("xxxxx").setFont(simsumFont);
Text attTableTitle7 = new Text("xx差").setFont(simsumFont);
Text attTableTitle8 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle9 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle10 = new Text("xxxxx").setFont(simsumFont);
Text attTableValue1 = new Text("xxxx").setFont(simsumFont);
Text attTableValue2 = new Text("5.6").setFont(simsumFont);
Text attTableValue3 = new Text("xxxx").setFont(simsumFont);
Text attTableValue4 = new Text("xxxxxxxxx").setFont(simsumFont);
Text attTableValue5 = new Text("xxx").setFont(simsumFont);
Text attTableValue6 = new Text("7").setFont(simsumFont);
Text attTableValue7 = new Text("1").setFont(simsumFont);
Text attTableValue8 = new Text("~3.5(含)").setFont(simsumFont);
Text attTableValue9 = new Text("5.5~6.5(含)").setFont(simsumFont);
Text attTableValue10 = new Text("6.5(含)").setFont(simsumFont);
defensiveAttributesTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(attTitle).setBold().setFontSize(FONT16)).addStyle(topLeftStyle)).setMarginTop(TABLE_MARGIN_TOP);
defensiveAttributesTable.addCell(new Cell(0, 8).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.BOTTOM)
.add(new Paragraph().add(attDes)).addStyle(topRightStyle)).setMarginTop(TABLE_MARGIN_TOP).setFontSize(FONT4);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle1).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle2).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle3).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle4).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle5).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle6).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle7).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle8).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle9).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment
(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle10).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftRightBottomStyle)).setFontSize(FONT10);
for (int i = 0; i < 4; i++) {
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue1)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue2)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue3)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue4)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue5)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue6)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue7)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue8)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue9)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
defensiveAttributesTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue10)).setTextAlignment(TextAlignment.CENTER).addStyle(leftRightBottomStyle)).setFontSize(FONT10);
return defensiveAttributesTable;
* xxxxxxx
public Table willQualityTable() {
Table willQualityTable = new Table(attackTableColumnWidth);
Text attTitle = new Text("xxxxxx").setFont(simsumFont);
Text attDes = new Text("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").setFont(simsumFont);
Text attTableTitle1 = new Text("xx").setFont(simsumFont);
Text attTableTitle2 = new Text("xx").setFont(simsumFont);
Text attTableTitle3 = new Text("xx").setFont(simsumFont);
Text attTableTitle4 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle5 = new Text("xxxx").setFont(simsumFont);
Text attTableTitle6 = new Text("xxx").setFont(simsumFont);
Text attTableTitle7 = new Text("xxx").setFont(simsumFont);
Text attTableTitle8 = new Text("xxx").setFont(simsumFont);
Text attTableTitle9 = new Text("xxx").setFont(simsumFont);
Text attTableTitle10 = new Text("xxx").setFont(simsumFont);
Text attTableValue1 = new Text("xxxx").setFont(simsumFont);
Text attTableValue2 = new Text("5.6").setFont(simsumFont);
Text attTableValue3 = new Text("xxx").setFont(simsumFont);
Text attTableValue4 = new Text("xxxxxxx").setFont(simsumFont);
Text attTableValue5 = new Text("xxx").setFont(simsumFont);
Text attTableValue6 = new Text("7").setFont(simsumFont);
Text attTableValue7 = new Text("1").setFont(simsumFont);
Text attTableValue8 = new Text("~3.5(含)").setFont(simsumFont);
Text attTableValue9 = new Text("5.5~6.5(含)").setFont(simsumFont);
Text attTableValue10 = new Text("6.5(含)").setFont(simsumFont);
willQualityTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(attTitle).setBold().setFontSize(FONT16)).addStyle(topLeftStyle)).setMarginTop(TABLE_MARGIN_TOP);
willQualityTable.addCell(new Cell(0, 8).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.BOTTOM)
.add(new Paragraph().add(attDes)).addStyle(topRightStyle)).setMarginTop(TABLE_MARGIN_TOP).setFontSize(FONT4);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle1).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle2).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle3).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle4).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle5).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle6).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle7).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle8).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle9).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_25).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableTitle10).setBold()).setTextAlignment(TextAlignment.CENTER).addStyle(topLeftRightBottomStyle)).setFontSize(FONT10);
for (int i = 0; i < 6; i++) {
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue1)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue2)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell
(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue3)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue4)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue5)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue6)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue7)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue8)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue9)).setTextAlignment(TextAlignment.CENTER).addStyle(leftBottomStyle)).setFontSize(FONT10);
willQualityTable.addCell(new Cell().setHeight(TABLE_HEIGHT_44).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().add(attTableValue10)).setTextAlignment(TextAlignment.CENTER).addStyle(leftRightBottomStyle)).setFontSize(FONT10);
return willQualityTable;
public Table adviceTable() {
Table willQualityTable = new Table(headerTableColumnWidth);
Text attTitle = new Text("xxxxxx").setFont(simsumFont);
String attContent = "1、xx建议xx建你好议xx建议xx建议xx建议优秀xx建议xx建议xx建议xx建议xx建议xx建议xx建xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议999999";
String attContent2 = "2、xx建议xx建议xx建议xx建议xx建议xx建议xx建你好议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议999999";
String attContent3 = "3、xx建议xx建议xx建议xx建议xx建议xx建议xx建你好议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议xx建议999999";
willQualityTable.addCell(new Cell(0, 2).setHeight(TABLE_HEIGHT_35).setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(new Paragraph().setMarginLeft(5).add(attTitle).setBold().setFontSize(FONT20)).addStyle(topLeftStyle)).setMarginTop(TABLE_MARGIN_TOP);
willQualityTable.addCell(new Cell(0, 2).setVerticalAlignment(VerticalAlignment.BOTTOM)
.add(new Paragraph().setFirstLineIndent(20).add(returnCorrectColor(attContent)))
.add(new Paragraph().setFirstLineIndent(20).add(returnCorrectColor(attContent2)))
.add(new Paragraph().setFirstLineIndent(20).add(returnCorrectColor(attContent3)))
.add(new Paragraph().setFirstLineIndent(20).add(returnCorrectColor("你好")))
.addStyle(topLeftRightBottomStyle)).setMarginTop(TABLE_MARGIN_TOP).setFontSize(FONT10);
return willQualityTable;
private Text returnCorrectColor(String letter) {
if ("有点好".equals(letter)){
return new Text("有点好").setFontColor(ColorConstants.YELLOW).setFont(simsumFont);
} else if ("不好".equals(letter)){
return new Text("不好").setFontColor(ColorConstants.GREEN).setFont(simsumFont);
} else if ("你好".equals(letter)) {
return new Text("你好")
.setFontColor(ColorConstants.RED).setFont(simsumFont);
}else {
return new Text(letter)
.setFontColor(ColorConstants.BLACK)
.setFont(simsumFont);
public static byte[] getStrToBytes(String imgStr) {
if (imgStr == null)
return null;
Base64.Decoder decoder = Base64.getDecoder();
try {
byte[] bytes = decoder.decode(imgStr);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {
bytes[i] += 256;
return bytes;
} catch (Exception e) {
return null;
4、结束语
本篇文章到这里就结束了,这篇文章主要讲述了Java使用第三方类库itext操作Pdf文档的用法。列举了一些常用的示例和一个精简的demo来讲述itext的用法。有想深入了解的同学可以参考官方的文档 。以及官方的示例demo 。