添加POM文件
<dependency>
<groupId>org.words</groupId>
<artifactId>words</artifactId>
<version>1.0</version>
</dependency>代码示例
import com.aspose.words.Document;
import java.io.File;
/**
* word转pdf工具类
*/
public class WordToPdfUtil {
/**
* word转成pdf工具类
* @param fromFile
* @param toFile
*/
public static void wordToPdfUtil(String fromFile,String toFile) {
try {
//doc路径
Document document = new Document(fromFile);
//pdf路径
File outputFile = new File(toFile);
//操作文档保存
document.save(outputFile.getAbsolutePath(), com.aspose.words.SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
//doc路径
Document document = new Document("C:\\Users\\lenovo\\Desktop\\新建文件夹\\qqq.docx");
//pdf路径
File outputFile = new File("C:\\Users\\lenovo\\Desktop\\新建文件夹\\qqq.pdf");
//操作文档保存
document.save(outputFile.getAbsolutePath(), com.aspose.words.SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}
}
}
1791

被折叠的 条评论
为什么被折叠?



