首先需要在pom.xml文件中添加依赖:
<!--iText-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
1、编写一个工具类:
package com.stylefeng.guns.core.util;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
/**
* @Description
* @autor: Yangwenhui
* @date: 2019/2/20 14:25
*/
public class PDFUtil {
/**
* 设置表格
* @param str 表格标题
* @param column 表格列数
* @param font 解决中文乱码的方法
* @return
* @throws Ba