<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.0</version>
</dependency>
import com.spire.doc.*;
/**
* 将Xml文件转换为Pdf文件
*
* @param fileName
* @param userTempFolder
*/
private void convertFile(String fileName, String userTempFolder) {
String file = userTempFolder + "/" + fileName;
String newFileName = file + ".pdf";
//创建Document类的对象
Document doc = new Document();
//加载XML文档
doc.loadFromFile(file, FileFormat.Xml);
//保存为PDF格式到指定路径
doc.saveToFile(newFileName, FileFormat.PDF);
}