0

Server Info: 4Core 8G Memory Office 2016 VL Windows Server 2012R2

testing file about 50mb size need takes over 800 seconds!

private static void wordToPdf(String wordFile, String pdfFile, String application) {
        Objects.requireNonNull(wordFile);
        Objects.requireNonNull(pdfFile);
        Objects.requireNonNull(application);

        ActiveXComponent ax = null;
        Dispatch document = null;
        try {
            File outFile = new File(pdfFile);
            // if parent target not exist and create
            if (!outFile.getParentFile().exists()) {
                Files.createDirectories(outFile.getParentFile().toPath());
            }

            //if exists and delete
            if (outFile.exists()) {
                outFile.delete();
            }

            ax = new ActiveXComponent(application);
            ax.setProperty("Visible", new Variant(false));
            ax.setProperty("AutomationSecurity", new Variant(3));

            Dispatch documents = ax.getProperty("Documents").toDispatch();
            document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch();

            Dispatch.call(document, "ExportAsFixedFormat", pdfFile, WORD_FORMAT_PDF);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            if (document != null) {
                Dispatch.call(document, "Close", false);
                document.safeRelease();
            }

            if (ax != null) {
                ax.invoke("Quit", 0);
                ax.safeRelease();
            }
        }
        ComThread.Release();
    }

i search document on stackoverflow or google and try to solve it, here is some measure:

  1. upgrade office version
  2. upgrade windows version
  3. expansion server resources(CPU CORE/SSD DISK)

at the beginning i thought it's office problem,now i want know,did anyone can tell me not use as above menthod can make convert speed faster

j_b
  • 1,975
  • 3
  • 8
  • 14

0 Answers0