freemarker生成了word 如何转换PDF

使用freemarker,使用mht方式,生成了带图片的doc文件。
有什么办法可以将doc文件转换成pdf文件(windows和linux通用)。

最好能给个例子。

可以使用itext,这个库支持转换pdf并且跨平台。

NItro PDF https://www.gonitro.com/download Windows

https://www.freepdfconvert.com/ Online convert

为什么要再多转一次呢,不浪费性能和时间么,用户端体验也不好。
需要word直接调用word方法,这样扩展也好。
再封装一个方法,freemarker直接转pdf。

如果业务需求的话:借鉴这个看看:
https://blog.csdn.net/qq_21306669/article/details/84313569

有网站是可以转的
推荐 迅捷在线pdf转word转换器

public void word2pdf(String source,String target){

ActiveXComponent app = null;

try {
ComThread.InitSTA();
app = new ActiveXComponent("Word.Application");

app.setProperty("Visible", false);

Dispatch docs = app.getProperty("Documents").toDispatch();

Dispatch doc = Dispatch.call(docs,"Open",source,false,true).toDispatch();

File tofile = new File(target);

if (tofile.exists()) {

tofile.delete();

}

Dispatch.call(doc,"SaveAs",target,wdFormatPDF);
Dispatch.call(doc, "Close", false);

} catch (Exception e) {
e.printStackTrace();
} finally {

if (app != null){
app.invoke("Quit", wdDoNotSaveChanges);
}
ComThread.Release();
}

}

word文档生成html模板(freemarker)再转为pdf:https://download.csdn.net/download/gongjin28_csdn/85118467