First download the jar
Here is the link address
Link: https://pan.baidu.com/s/1YaMIp4No9yzD7eSG4oMb_A Extraction code: wg1h
We need to import the jar package in idea
If you don't, look directly here:
https://blog.csdn.net/superinzaghi747/article/details/80539095
Then create an xml file under resource
Then go directly to the code:
/**
* 获取配置文件信息
*
* @return boolean
*/
public static boolean getLicense() {
try {
InputStream is = FileUtils.class.getClassLoader().getResourceAsStream("License.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
License license = new License();
license.setLicense(is);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 转换文件流
*
* @param Address 本地文件地址
*/
public static void doc2pdf(String Address) {
if (getLicense()) {
try {
long old = System.currentTimeMillis();
File file = new File("C:\\Users\\18701\\Downloads\\test.pdf");
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(Address); //Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF);//支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
long now = System.currentTimeMillis();
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("转化失败");
}
}
public static void main(String[] args) {
doc2pdf("C:\\Users\\18701\\Downloads\\1589765732905.doc");
}
If the download returns, just return to the stream file directly