一、引入相关jar包
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.13</version>
</dependency>
二、使用itextpdf生成pdf文件
2.1 创建目标文档
public String createDocument(String folderName,String fileName,Document document)
throws IOException {
String pdfPath = "/data/pdfFile";
// 如果文件夹不存在 则创建文件夹
File folder = new File(pdfPath);
if (!folder.exists()) {
folder.mkdirs();
}
folder.createNewFile();
String path = folder.getAbsolutePath();
// 存储文件
File file = new File(path, fileName);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
PdfWriter pdfWriter = PdfW