2017-06-30 276 views
1

我试图使用JOD Converter将文档(.docx/.xlsx/.pptx)转换为PDF。我在Centos 7上使用OpenOffice 4.1.2。我的问题是,当我转换文件时,我的CPU占用率达到了100%,这影响了整个机器的性能。我已经尝试了命令行选项中的所有可能的选项,但不幸的是,还没有能够缓解这个问题。我在很多论坛上搜索过,发现很多其他人也面临同样的问题,但是,这里没有解决方案。通过我的阅读,我意识到这可能是因为OpenOffice中的内存泄漏问题。有人可以帮助我解决或至少减轻这个问题吗?使用OpenOffice4时CPU利用率100%

下面是我用产卵OpenOffice的实例的命令。

/opt/openoffice4/program/soffice.bin -accept=socket,host=127.0.0.1,port=8016;urp; -env:UserInstallation=file:///tmp/.jodconverter_socket_host-127.0.0.1_port-8016 -headless -nocrashreport -nodefault -nofirststartwizard -nolockcheck -nologo -norestore 

的代码我使用的文件转换为: 包org.samples.docxconverters.jodconverter.pdf;

import java.io.File; 

import org.apache.commons.io.FilenameUtils; 
import org.artofsolving.jodconverter.OfficeDocumentConverter; 
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; 
import org.artofsolving.jodconverter.office.OfficeManager; 

public class Word2PdfJod { 

    public static void main(String[] args) { 

     // 1) Start LibreOffice in headless mode. 
     OfficeManager officeManager = null; 
     try { 
      officeManager = new DefaultOfficeManagerConfiguration() 
       .setOfficeHome(new File("/Applications/OpenOffice.app/Contents/")).buildOfficeManager(); 
      officeManager.start(); 

      // 2) Create JODConverter converter 
      OfficeDocumentConverter converter = new OfficeDocumentConverter(
        officeManager); 

      // 3) Create PDF 
      createPDF(converter); 

     } finally { 
      // 4) Stop OpenOffice in headless mode. 
      if (officeManager != null) { 
       officeManager.stop(); 
      } 
     } 
    } 

    private static void createPDF(OfficeDocumentConverter converter) { 
     try { 
      long start = System.currentTimeMillis(); 
      String src_file = "/Users/Aman/Documents/WindowsData/DocumentConversionPoc/Powerpoint2Pdf/JODConverterV3/Sample_pptx_files/AdeemSample2.pptx"; 

      System.out.println(src_file.substring(0, src_file.lastIndexOf(".")) + "_" + FilenameUtils.getExtension(src_file)); 
      //Actual Conversion 

      converter.convert(new File(src_file), new File(src_file.substring(0, src_file.lastIndexOf(".")) + "_" 
         + FilenameUtils.getExtension(src_file) +"_Jod.pdf")); 
      System.out.println("Time Taken in conversion - "+ (System.currentTimeMillis() - start) + "ms"); 


     } catch (Throwable e) { 
      e.printStackTrace(); 
     } 
    } 
} 

和相关的罐子可以从以下网址下载: https://drive.google.com/file/d/0B4hS5IGxGOh9OE5Ca0RlbTdVclU/view?usp=sharing

+0

避免约旦第纳尔转换器和使用Ghostscript打印文档 – deblocker

+0

@deblocker问题是与OpenOffice/LibreOffice,而不是JOD。仅供参考,我已经尝试过Ghostscript,它没有帮助。它进一步将转换分为两部分:Doc - > PostScript - > PDF。 它使转换时间增加了很多,这是我们真正想要保持的低位 – Geek

+0

我过去做过大量的pdf大量打印,尽管不是您的OO版本,GS一直是我的最佳选择。如果这对你没有帮助,我很害怕。祝你好运! – deblocker

回答

0

通过减少您的应用程序可以使用的核心数量,可以防止系统被锁定:

Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)2; 

To set the affinity of CPUs using C#