diff --git a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/LBContractTemplateList.jsp b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/LBContractTemplateList.jsp index 6ec464bc1..ea39d0a17 100644 --- a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/LBContractTemplateList.jsp +++ b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/LBContractTemplateList.jsp @@ -134,10 +134,12 @@ html+=''+getObj(0,i,"filename").innerHTML+''; getObj(0,i,"filename").innerHTML=html; if(fileid.length>0){ - if("<%=RightType%>"=="ReadOnly"){ - getObj(0,i,"operation").innerHTML='     '; - }else{ - getObj(0,i,"operation").innerHTML='        '; + if(getObj(0,i,"operation")!= null){ + if("<%=RightType%>"=="ReadOnly"){ + getObj(0,i,"operation").innerHTML='     '; + }else{ + getObj(0,i,"operation").innerHTML='        '; + } } } } diff --git a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/contract_template.jsp b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/contract_template.jsp index 0157b29ea..1ec68f8d6 100644 --- a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/contract_template.jsp +++ b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/contract_template.jsp @@ -269,156 +269,184 @@ $("#filetemplatemodel").append(""); } - function createContractByTemplate(){ - var checkbox=$("#filetemplatemodel").html()||""; - if(checkbox==""){alert("请选择合同模板下面的分类,或分类下面没有模板");return false;} - var tempids=""; - $('input[name="fileTemplate"]:checked').each(function(){ - if(tempids.length>0){ - tempids+="&"; - } - tempids += $(this).attr('value'); - }); - if(tempids.length<=0){ - alert("请勾选合同模板!"); - return; - } - if("BContractChangeApply"!="<%=CurPage.getParameter("ApplyType")%>"){ - var contractNomessage = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil","CheckContractNo","contractId="+"<%=sContractId%>"+",contractNo="+"<%=CurPage.getParameter("ContractNo")%>"); - if("error"==contractNomessage){ - alert("合同编号重复,请联系后台人员处理!"); - return; - } - } - var message = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil","CheckCar","contractId="+"<%=sContractId%>"+",templateIds="+tempids+",flowunid="+"<%=flowunid%>"+",operationType="+"<%=CurPage.getParameter("operationType")%>"); - if(""!=message){ - if("01"=="<%=customertype%>"){ - if(message.indexOf("请先删除后再生成")>0){ - alert("合同已生成,无法再次生成!"); - location.reload(); - return; - } - } - alert(message); - location.reload(); - return; - } - //检查扣款卡信息是否签约 - var sReturnInfo = RunJavaMethodTrans("com.tenwa.lease.flow.contract.check.ContractInfoCheck","ProjectSignStatus","projectid=<%=projectId%>"); - if("success"!=sReturnInfo){ - alert(sReturnInfo); - return; - } - var param={}; - var tempParam={}; - var sparam=""; - // param["templateNo"]="0010"; - tempParam["CurUserId"]="<%=CurUser.getUserID()%>"; - tempParam["CurOrgId"]="<%=CurUser.getOrgID()%>"; - tempParam["OBJECTTYPE"]="<%=CurPage.getParameter("FLOW_NO")%>"; - tempParam["FLOW_UNID"]="<%=flowunid%>"; - tempParam["CONTRACT_ID"]="<%=sContractId%>"; - tempParam["PROJ_ID"]="<%=sProjId%>"; - tempParam["PROJECT_ID"]="<%=projectId%>"; - tempParam["contractNo"]="<%=contractNo%>"; - tempParam["certid"]="<%=certid%>"; - tempParam["mobile"]="<%=mobile%>"; - tempParam["address"]="<%=address%>"; - tempParam["NETMORTGAGOR"]="<%=NetMortgagor%>"; - tempParam["NETCERTID"]="<%=NetCertid%>"; - tempParam["NETMOBILE"]="<%=NetMobile%>"; - tempParam["NETADDRESS"]="<%=Netaddress%>"; - tempParam["fileSavePath"]="<%=CurConfig.getConfigure("FileSavePath")%>"; + function popupShade() { + var d = top.dialog({ + callbacks: { + cancel: function () { + return false + } + }, + width: '200', + height: '40', + innerHTML: '正在执行中......' + }); + d.showModal(); + return d; + } - //专用车产品、网约车、大通 使用手签的模板生成合同 - var operationType2 = "<%=CurPage.getParameter("operationType")%>"; - //alert(operationType2); - if("ZYC"==operationType2||"WYC"==operationType2||"DT"==operationType2){ - param["templateIds"]='5c494617683548a49cfc050f60067ea2';//选择的模板ID - }else{ - param["templateIds"]=tempids;//选择的模板ID - } + function createContractByTemplate() { + var d = popupShade(); + setTimeout(function () { + var checkbox = $("#filetemplatemodel").html() || ""; + if (checkbox == "") { + alert("请选择合同模板下面的分类,或分类下面没有模板"); + return false; + } + var tempids = ""; + $('input[name="fileTemplate"]:checked').each(function () { + if (tempids.length > 0) { + tempids += "&"; + } + tempids += $(this).attr('value'); + }); + if (tempids.length <= 0) { + alert("请勾选合同模板!"); + d.close().remove(); + return; + } + if ("BContractChangeApply" != "<%=CurPage.getParameter("ApplyType")%>") { + var contractNomessage = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil", "CheckContractNo", "contractId=" + "<%=sContractId%>" + ",contractNo=" + "<%=CurPage.getParameter("ContractNo")%>"); + if ("error" == contractNomessage) { + alert("合同编号重复,请联系后台人员处理!"); + d.close().remove(); + return; + } + } + var message = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil", "CheckCar", "contractId=" + "<%=sContractId%>" + ",templateIds=" + tempids + ",flowunid=" + "<%=flowunid%>" + ",operationType=" + "<%=CurPage.getParameter("operationType")%>"); + if ("" != message) { + if ("01" == "<%=customertype%>") { + if (message.indexOf("请先删除后再生成") > 0) { + alert("合同已生成,无法再次生成!"); + d.close().remove(); + return; + } + } + alert(message); + d.close().remove(); + return; + } + //检查扣款卡信息是否签约 + var sReturnInfo = RunJavaMethodTrans("com.tenwa.lease.flow.contract.check.ContractInfoCheck", "ProjectSignStatus", "projectid=<%=projectId%>"); + if ("success" != sReturnInfo) { + alert(sReturnInfo); + d.close().remove(); + return; + } + var param = {}; + var tempParam = {}; + var sparam = ""; + // param["templateNo"]="0010"; + tempParam["CurUserId"] = "<%=CurUser.getUserID()%>"; + tempParam["CurOrgId"] = "<%=CurUser.getOrgID()%>"; + tempParam["OBJECTTYPE"] = "<%=CurPage.getParameter("FLOW_NO")%>"; + tempParam["FLOW_UNID"] = "<%=flowunid%>"; + tempParam["CONTRACT_ID"] = "<%=sContractId%>"; + tempParam["PROJ_ID"] = "<%=sProjId%>"; + tempParam["PROJECT_ID"] = "<%=projectId%>"; + tempParam["contractNo"] = "<%=contractNo%>"; + tempParam["certid"] = "<%=certid%>"; + tempParam["mobile"] = "<%=mobile%>"; + tempParam["address"] = "<%=address%>"; + tempParam["NETMORTGAGOR"] = "<%=NetMortgagor%>"; + tempParam["NETCERTID"] = "<%=NetCertid%>"; + tempParam["NETMOBILE"] = "<%=NetMobile%>"; + tempParam["NETADDRESS"] = "<%=Netaddress%>"; - //20210922 合同模板调整 + tempParam["fileSavePath"] = "<%=CurConfig.getConfigure("FileSavePath")%>"; - // 客户手签(通用C端售后回租合同) 乘用车手签 - // 乘用车售后回租电子签约 乘用车电子签约 - // 专用车产品、商用车一车一挂 商用车手签 - // 商用车一车一挂电子签约 商用车电子签约 - - if("KHSQ"==operationType2){ - param["templateIds"]='f57aa80567853aa37fd6dd902021a';//选择的模板ID - tempids='f57aa80567853aa37fd6dd902021a'; - }else if("CYSHDZ"==operationType2){ - param["templateIds"]='f57aa80567853aa37fd6dd902021b';//选择的模板ID - tempids='f57aa80567853aa37fd6dd902021b'; - }else if("ZYC"==operationType2||"SYCSHHZ"==operationType2){ - param["templateIds"]='f57aa80567853aa37fd6dd902021c';//选择的模板ID - tempids='f57aa80567853aa37fd6dd902021c'; - }else if("SYCSHHZDZQ"==operationType2){ - param["templateIds"]='f57aa80567853aa37fd6dd902021d';//选择的模板ID - tempids='f57aa80567853aa37fd6dd902021d'; - } - - param["templateParam"]=JSON.stringify(tempParam).replace(/,/g,"@");//生成模板的参数据 - for(var key in param){ - if(sparam.length>0){sparam+=",";} - sparam+=key+"="+param[key]; - } - - var sReturn0 = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil","createContractTemplate",sparam); - - if(sReturn0.length>2){ - alert(sReturn0); - }else{ - var pdfPath=RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","wordToPdf","FlowUnid=<%=flowunid%>,flagType=word"); -<%-- if("01"=="<%=customertype%>"||"1"=="<%=CurPage.getParameter("isNetCar")%>"||"BAIC_MOTOR"=="<%=CurPage.getParameter("operationType")%>"||"ZYC"=="<%=CurPage.getParameter("operationType")%>"||"KHSQ"=="<%=CurPage.getParameter("operationType")%>"||"KJZL"=="<%=CurPage.getParameter("operationType")%>"){ --%> - var operationType = "<%=CurPage.getParameter("operationType")%>"; - - if("ZC"!=operationType){ - var OwmMessage = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","SystemMakeOneDimensionalCode","ProjectId=<%=projectId%>,contract_id=<%=sContractId%>,contractNo=<%=contractNo%>,leasform=<%=leasform%>"); - if("error"==OwmMessage){ - RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","companyUpdateDocContractStatus","FlowUnid=<%=flowunid%>"+",ProjectId=<%=projectId%>"); - alert("生成失败1!!!"); - reloadSelf(); - return; - } - }else{ - //中车pdf添加水印 - var OwmMessage = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","SystemMakeOneDimensionalCode","ProjectId=<%=projectId%>,contract_id=<%=sContractId%>,contractNo=<%=contractNo%>,leasform=<%=leasform%>"); + //专用车产品、网约车、大通 使用手签的模板生成合同 + var operationType2 = "<%=CurPage.getParameter("operationType")%>"; + //alert(operationType2); + if ("ZYC" == operationType2 || "WYC" == operationType2 || "DT" == operationType2) { + param["templateIds"] = '5c494617683548a49cfc050f60067ea2';//选择的模板ID + } else { + param["templateIds"] = tempids;//选择的模板ID } - if(("01"=="<%=customertype%>"&&"Auto" == "<%=sealType%>" )||("Auto" == "<%=sealType%>" && "Hand" == "<%=signType%>" )){ - var falg = ""; + //20210922 合同模板调整 - if("LHZL"==operationType || "SQSYC"==operationType){ - falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionTwo","compnySignIng","FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,operationType="+operationType); - //商用车一车一挂、专用车产品、网约车、大通、C端直租、客户手签、商用车手签、乘用车手签 - }else if ("SYCSHHZ"==operationType||"ZYC"==operationType||"WYC"==operationType||"DT"==operationType||"CDZZ"==operationType - ||"CYCSQ"==operationType ||"KHSQ"==operationType ||"SYCSQ"==operationType||"5c494617683548a49cfc050f60067ea2"==tempids){ - falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionTwoOwn","compnySignIng","FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,tempid="+tempids); - }else if("ZC"==operationType){ - falg="success"; - }else if("KJLHZL"==operationType||"KJLHZLCYC"==operationType||"KJLHZLSYC"==operationType ||"KJCYYQR"==operationType - ||"KJSYYQR"==operationType||"CYCDZQ"==operationType||"SYCDZQ"==operationType){//凯捷联合租赁商用车手签、乘用车手签 - // alert("凯捷联合租赁,合同模板id=" + tempids); - falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionNewUtils","compnySignIng","FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,operationType="+operationType); - } else{ - falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","compnySignIng","FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>"); - } - if("success"!= falg ){ - RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction","companyUpdateDocContractStatus","FlowUnid=<%=flowunid%>"+",ProjectId=<%=projectId%>"); - alert("生成失败!!!"); - reloadSelf(); - return; - } - } + // 客户手签(通用C端售后回租合同) 乘用车手签 + // 乘用车售后回租电子签约 乘用车电子签约 + // 专用车产品、商用车一车一挂 商用车手签 + // 商用车一车一挂电子签约 商用车电子签约 - alert("生成成功"); - } - reloadSelf(); - } + if ("KHSQ" == operationType2) { + param["templateIds"] = 'f57aa80567853aa37fd6dd902021a';//选择的模板ID + tempids = 'f57aa80567853aa37fd6dd902021a'; + } else if ("CYSHDZ" == operationType2) { + param["templateIds"] = 'f57aa80567853aa37fd6dd902021b';//选择的模板ID + tempids = 'f57aa80567853aa37fd6dd902021b'; + } else if ("ZYC" == operationType2 || "SYCSHHZ" == operationType2) { + param["templateIds"] = 'f57aa80567853aa37fd6dd902021c';//选择的模板ID + tempids = 'f57aa80567853aa37fd6dd902021c'; + } else if ("SYCSHHZDZQ" == operationType2) { + param["templateIds"] = 'f57aa80567853aa37fd6dd902021d';//选择的模板ID + tempids = 'f57aa80567853aa37fd6dd902021d'; + } + + param["templateParam"] = JSON.stringify(tempParam).replace(/,/g, "@");//生成模板的参数据 + for (var key in param) { + if (sparam.length > 0) { + sparam += ","; + } + sparam += key + "=" + param[key]; + } + + var sReturn0 = RunJavaMethodTrans("com.tenwa.app.baseFileTemplate.handle.FileTemplateUtil", "createContractTemplate", sparam); + + if (sReturn0.length > 2) { + alert(sReturn0); + d.close().remove(); + } else { + var pdfPath = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "wordToPdf", "FlowUnid=<%=flowunid%>,flagType=word"); + <%-- if("01"=="<%=customertype%>"||"1"=="<%=CurPage.getParameter("isNetCar")%>"||"BAIC_MOTOR"=="<%=CurPage.getParameter("operationType")%>"||"ZYC"=="<%=CurPage.getParameter("operationType")%>"||"KHSQ"=="<%=CurPage.getParameter("operationType")%>"||"KJZL"=="<%=CurPage.getParameter("operationType")%>"){ --%> + var operationType = "<%=CurPage.getParameter("operationType")%>"; + + if ("ZC" != operationType) { + var OwmMessage = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "SystemMakeOneDimensionalCode", "ProjectId=<%=projectId%>,contract_id=<%=sContractId%>,contractNo=<%=contractNo%>,leasform=<%=leasform%>"); + if ("error" == OwmMessage) { + RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "companyUpdateDocContractStatus", "FlowUnid=<%=flowunid%>" + ",ProjectId=<%=projectId%>"); + alert("生成失败1!!!"); + d.close().remove(); + return; + } + } else { + //中车pdf添加水印 + var OwmMessage = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "SystemMakeOneDimensionalCode", "ProjectId=<%=projectId%>,contract_id=<%=sContractId%>,contractNo=<%=contractNo%>,leasform=<%=leasform%>"); + } + + if (("01" == "<%=customertype%>" && "Auto" == "<%=sealType%>") || ("Auto" == "<%=sealType%>" && "Hand" == "<%=signType%>")) { + var falg = ""; + + if ("LHZL" == operationType || "SQSYC" == operationType) { + falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionTwo", "compnySignIng", "FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,operationType=" + operationType); + //商用车一车一挂、专用车产品、网约车、大通、C端直租、客户手签、商用车手签、乘用车手签 + } else if ("SYCSHHZ" == operationType || "ZYC" == operationType || "WYC" == operationType || "DT" == operationType || "CDZZ" == operationType + || "CYCSQ" == operationType || "KHSQ" == operationType || "SYCSQ" == operationType || "5c494617683548a49cfc050f60067ea2" == tempids) { + falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionTwoOwn", "compnySignIng", "FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,tempid=" + tempids); + } else if ("ZC" == operationType) { + falg = "success"; + } else if ("KJLHZL" == operationType || "KJLHZLCYC" == operationType || "KJLHZLSYC" == operationType || "KJCYYQR" == operationType + || "KJSYYQR" == operationType || "CYCDZQ" == operationType || "SYCDZQ" == operationType) {//凯捷联合租赁商用车手签、乘用车手签 + // alert("凯捷联合租赁,合同模板id=" + tempids); + falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignActionNewUtils", "compnySignIng", "FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>,operationType=" + operationType); + } else { + falg = RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "compnySignIng", "FlowUnid=<%=flowunid%>,flagType=word,ProjectId=<%=projectId%>,SubjectId=<%=SubjectId%>"); + } + if ("success" != falg) { + RunJavaMethodTrans("com.tenwa.channelportal.action.ContractSignAction", "companyUpdateDocContractStatus", "FlowUnid=<%=flowunid%>" + ",ProjectId=<%=projectId%>"); + alert("生成失败!!!"); + d.close().remove(); + return; + } + } + alert("生成成功"); + d.close().remove(); + } + reloadSelf(); + }, '200'); + } function downloadFile(id){ if(!frames["downloadTemplate"]) $("").appendTo("body"); window.open(sWebRootPath+"/servlet/view/docDownloadServlet?CompClientID=<%=sCompClientID%>&sqlString=save@"+id, "downloadTemplate"); diff --git a/config/license.xml b/config/license.xml new file mode 100644 index 000000000..911bebd8f --- /dev/null +++ b/config/license.xml @@ -0,0 +1,14 @@ + + + + + Aspose.Total for Java + Aspose.Words for Java + + Enterprise + 20991231 + 20991231 + 8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7 + + sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU= + \ No newline at end of file diff --git a/src/com/tenwa/channelportal/action/generativecontract/WordToPDFUtil.java b/src/com/tenwa/channelportal/action/generativecontract/WordToPDFUtil.java index 5c5937790..2caa1c6d5 100644 --- a/src/com/tenwa/channelportal/action/generativecontract/WordToPDFUtil.java +++ b/src/com/tenwa/channelportal/action/generativecontract/WordToPDFUtil.java @@ -1,57 +1,89 @@ package com.tenwa.channelportal.action.generativecontract; -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStreamReader; +import com.aspose.words.Document; +import com.aspose.words.SaveFormat; +import com.tenwa.httpclient.resources.QuartzPropertiesUtil; import org.apache.log4j.Logger; -import com.tenwa.httpclient.resources.QuartzPropertiesUtil; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStreamReader; + public class WordToPDFUtil { - private static Logger logger = Logger.getLogger(WordToPDFUtil.class); - // 将word格式的文件转换为pdf格式 - public synchronized static Boolean Word2Pdf(String srcPath, String desPath) throws Exception { - // 源文件目录 - File inputFile = new File(srcPath); - if (!inputFile.exists()) { - System.out.println("word转换pdf,源文件不存在"); - return false; - } - // 输出文件目录 - File outputFile = new File(desPath); - if (!outputFile.getParentFile().exists()) { - outputFile.getParentFile().mkdirs(); - } - Process process = null; - //获取当前时间的毫秒数 - long start= System.currentTimeMillis(); - logger.info("============转换pdf开始============"); - try{ - String path = QuartzPropertiesUtil.get("libreOffice_path"); - String cmd = path+"soffice --headless -invisible --convert-to pdf "+srcPath+" --outdir "+desPath; - logger.info("python:"+cmd); - process = Runtime.getRuntime().exec(cmd); - String cmdMsg = ""; - BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); - while((cmdMsg=bufferedReader.readLine()) !=null){ - logger.info(cmdMsg); - } - process.waitFor(); - }catch(Exception e){ - e.printStackTrace(); - return false; - }finally{ - if(null!=process){ - process.destroy(); - } - long end = System.currentTimeMillis(); - //输出转换pdf所需毫秒数 - logger.info(end-start+"毫秒"); - logger.info("============转换pdf结束============"); - } - return true; - } - - public static void main(String[] args) throws Exception { - WordToPDFUtil.Word2Pdf("d:\\1、光大金融租赁公司融资租赁合同(法人)—保证保险模式.doc", "d:\\woqu"); - } + private static Logger logger = Logger.getLogger(WordToPDFUtil.class); + + public synchronized static Boolean Word2Pdf(String inPath, String outPath) throws Exception { + // 验证License 若不验证则转化出的pdf文档会有水印产生 + if (!Word2PdfUtil.getLicense()) { + throw new RuntimeException("转PDF工具,验证License失败"); + } + if (inPath.contains(".doc")) outPath = inPath.replace(".docx", ".pdf").replace(".doc", ".pdf"); + File inputFile = new File(inPath); + if (!inputFile.exists()) { + logger.error("word转换pdf,源文件不存在:" + inPath); + return false; + } + try { + long old = System.currentTimeMillis(); + logger.info("============转换pdf开始============"); + File file = new File(outPath); + FileOutputStream os = new FileOutputStream(file); + Document doc = new Document(inPath); + doc.save(os, SaveFormat.PDF); + logger.info("共耗时:" + (System.currentTimeMillis() - old) + "毫秒"); + logger.info("============转换pdf结束============"); + } catch (Exception e) { + logger.error(e.getMessage()); + return false; + } + return true; + } + + // 将word格式的文件转换为pdf格式 + public synchronized static Boolean Word2Pdf1(String srcPath, String desPath) throws Exception { + // 源文件目录 + File inputFile = new File(srcPath); + if (!inputFile.exists()) { + System.out.println("word转换pdf,源文件不存在"); + return false; + } + // 输出文件目录 + File outputFile = new File(desPath); + if (!outputFile.getParentFile().exists()) { + outputFile.getParentFile().mkdirs(); + } + Process process = null; + //获取当前时间的毫秒数 + long start = System.currentTimeMillis(); + logger.info("============转换pdf开始============"); + try { + String path = QuartzPropertiesUtil.get("libreOffice_path"); + String cmd = path + "soffice --headless -invisible --convert-to pdf " + srcPath + " --outdir " + desPath; + logger.info("python:" + cmd); + process = Runtime.getRuntime().exec(cmd); + String cmdMsg = ""; + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + while ((cmdMsg = bufferedReader.readLine()) != null) { + logger.info(cmdMsg); + } + process.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (null != process) { + process.destroy(); + } + long end = System.currentTimeMillis(); + //输出转换pdf所需毫秒数 + logger.info(end - start + "毫秒"); + logger.info("============转换pdf结束============"); + } + return true; + } + + public static void main(String[] args) throws Exception { + WordToPDFUtil.Word2Pdf("d:\\1、光大金融租赁公司融资租赁合同(法人)—保证保险模式.doc", "d:\\woqu"); + } }