Open yujunchengg opened 8 months ago
Where did you get new Variant(32)
from? It's supposed to be 0 or -1. https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentations.open and https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.core.msotristate?view=office-pia
My program runs in the following environmen windows server 2016 Standard 64 bit Microsoft Office Professional 2016 jdk version: 1.8.0 (build 1.8.0_221-b11) jacob version: 1.20 The program code is as follows public static FileConvertResult ppt2PDF(String pptfile, String pdffile){ if(Files.exists(Paths.get(pdffile))){ return new FileConvertResult(true,false); } synchronized (pptfile.intern()){ FileConvertResult result = new FileConvertResult(true,false); if(Files.exists(Paths.get(pdffile))){ log.info("current thread: {} do not need to execute ppt2PDF method, because other thread has execute ppt2PDF method",Thread.currentThread().getName()); return result; } ActiveXComponent ppt = null; Dispatch presentations = null; try { ComThread.InitMTA(true); ppt = new ActiveXComponent("PowerPoint.application"); Dispatch.put(ppt.getObject(), "DisplayAlerts", new Variant(false)); presentations = ppt.invokeGetComponent("Presentations").invokeGetComponent("Open", new Variant(pptfile)); Dispatch.invoke(presentations, "SaveAs", Dispatch.Method, new Object[] {pdffile , new Variant(32) }, new int[1]); } catch (Exception e) { log.error("-------------ppt2PDF occurred exception----------"); String message = e.getMessage(); result.setSuccess(false); result.setNeedReconvert(true); result.setDescription(message); /if(null!=message){ if(message.contains("Description: ")){ result.setNeedReconvert(false); } }/ log.error(result.getDescription(), e); } finally { try { if (ppt != null) { ppt.invoke("Quit"); } } catch (Exception e1) { log.error(e1.getMessage(),e1); } finally { if (presentations != null){ presentations.safeRelease(); } if (ppt != null){ ppt.safeRelease(); } ComThread.Release(); } } return result; } }
Strangely enough it can work well on Windows server 2012,but on Windows server 2016,it occurred exception,exception detail message is that: com.jacob.com.ComFailException: Invoke of: Open Source: Description: