Primero descarga el frasco
Aquí está la dirección del enlace
Enlace: https://pan.baidu.com/s/1YaMIp4No9yzD7eSG4oMb_A Código de extracción: wg1h
Necesitamos importar el paquete jar en idea.
Si no es así, mire directamente aquí:
https://blog.csdn.net/superinzaghi747/article/details/80539095
Luego crea un archivo xml en recurso
Luego vaya directamente al código:
/**
* 获取配置文件信息
*
* @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");
}
Si la descarga regresa, simplemente regrese al archivo de flujo directamente