Java Code Examples for org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration#buildOfficeManager()

The following examples show how to use org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration#buildOfficeManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseTests.java    From kbase-doc with Apache License 2.0 8 votes vote down vote up
protected void convert(File inputFile, File outputFile){
		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
		configuration.setPortNumber(8100);
		configuration.setOfficeHome(new File(libreOfficeDirPath));
//		configuration.setOfficeHome(new File("D:/Program Files/OpenOffice"));

		OfficeManager officeManager = configuration.buildOfficeManager();
        officeManager.start();
        DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
        OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry);
        
        try {
        	 converter.convert(inputFile, outputFile);
        } catch (Exception e){
        	e.printStackTrace();
		} finally {
            officeManager.stop();
        }
	}
 
Example 2
Source File: BaseTests.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
protected void convert(File inputFile, File outputFile, String password){
		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
		configuration.setPortNumber(8100);
		configuration.setOfficeHome(new File(libreOfficeDirPath));
//		configuration.setOfficeHome(new File("D:/Program Files/OpenOffice"));

		OfficeManager officeManager = configuration.buildOfficeManager();
        officeManager.start();
        DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
        OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry);
        Map<String,?> defaultLoadProperties = createDefaultLoadProperties(password);
        converter.setDefaultLoadProperties(defaultLoadProperties);
        try {
        	 converter.convert(inputFile, outputFile);
        } catch (Exception e){
        	e.printStackTrace();
		} finally {
            officeManager.stop();
        }
	}
 
Example 3
Source File: ConvertTests.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
@Test
	public void testConvert() throws IOException {
//		File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.doc");
		File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1512561737109.html");
		File outputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/" + Calendar.getInstance().getTimeInMillis() + ".docx");
//		if (!outputFile.exists()){
//			outputFile.createNewFile();
//		}
		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
		configuration.setPortNumber(8100);
		configuration.setOfficeHome(new File("D:/Program Files/LibreOffice"));

		OfficeManager officeManager = configuration.buildOfficeManager();
        officeManager.start();
        DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
        OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry);
        
        try {
        	 converter.convert(inputFile, outputFile);
        } catch (Exception e){
        	e.printStackTrace();
		} finally {
            officeManager.stop();
        }
	}
 
Example 4
Source File: ConverterUtils.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void initOfficeManager() {
    File officeHome;
    officeHome = OfficeUtils.getDefaultOfficeHome();
    if (officeHome == null) {
        throw new RuntimeException("找不到office组件,请确认'office.home'配置是否有误");
    }
    boolean killOffice = killProcess();
    if (killOffice) {
        logger.warn("检测到有正在运行的office进程,已自动结束该进程");
    }
    try {
        DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
        configuration.setOfficeHome(officeHome);
        configuration.setPortNumber(8100);
        // 设置任务执行超时为5分钟
        configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
        // 设置任务队列超时为24小时
        //configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
        officeManager = configuration.buildOfficeManager();
        officeManager.start();
    } catch (Exception e) {
        logger.error("启动office组件失败,请检查office组件是否可用");
        throw e;
    }
}
 
Example 5
Source File: OfficeConService.java    From wenku with MIT License 6 votes vote down vote up
/**
 * 
 * 创建一个新的实例 OfficeConService.
 */
public OfficeConService() {

    DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();

    //设置转换端口,默认为2002
    if (StringUtils.isNotBlank(this.officePort)) {
        configuration.setPortNumber(Integer.parseInt(this.officePort));
        logger.info("office转换服务监听端口设置为:" + this.officePort);
    }

    //设置office安装目录
    if (StringUtils.isNotBlank(officeHome)) {
        configuration.setOfficeHome(new File(this.officeHome));
        logger.info("设置office安装目录为:" + this.officeHome);
    }

    officeManager = configuration.buildOfficeManager();
    documentConverter = new OfficeDocumentConverter(this.officeManager);
}
 
Example 6
Source File: OfficeConService.java    From wenku with MIT License 6 votes vote down vote up
/**
 * 
 * 创建一个新的实例 OfficeConService.
 * @param officePort
 * @param officeHome
 */
public OfficeConService(String officePort, String officeHome) {
    this.officePort = officePort;
    this.officeHome = officeHome;

    DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();

    //设置转换端口,默认为8100
    if (StringUtils.isNotBlank(this.officePort)) {
        configuration.setPortNumber(Integer.parseInt(this.officePort));
        logger.info("office转换服务监听端口设置为:" + this.officePort);
    }

    //设置office安装目录
    if (StringUtils.isNotBlank(this.officeHome)) {
        configuration.setOfficeHome(new File(this.officeHome));
        logger.info("设置office安装目录为:" + this.officeHome);
    }

    officeManager = configuration.buildOfficeManager();
    documentConverter = new OfficeDocumentConverter(officeManager);
}
 
Example 7
Source File: OpenOfficePDFConverter.java    From jeewx with Apache License 2.0 6 votes vote down vote up
public static void startService() {
	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	try {
		// 准备启动服务
		configuration.setOfficeHome(OFFICE_HOME);// 设置OpenOffice.org安装目录
		// 设置转换端口,默认为8100
		configuration.setPortNumbers(port);
		// 设置任务执行超时为5分钟
		configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
		// 设置任务队列超时为24小时
		configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);

		officeManager = configuration.buildOfficeManager();
		officeManager.start(); // 启动服务
		org.jeecgframework.core.util.LogUtil.info("office转换服务启动成功!");
	} catch (Exception ce) {
		org.jeecgframework.core.util.LogUtil.info("office转换服务启动失败!详细信息:" + ce);
	}
}
 
Example 8
Source File: OpenOfficePDFConverter.java    From jeecg with Apache License 2.0 6 votes vote down vote up
public static void startService() {
	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	try {
		// 准备启动服务
		configuration.setOfficeHome(OFFICE_HOME);// 设置OpenOffice.org安装目录
		// 设置转换端口,默认为8100
		configuration.setPortNumbers(port);
		// 设置任务执行超时为5分钟
		configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
		// 设置任务队列超时为24小时
		configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);

		officeManager = configuration.buildOfficeManager();
		officeManager.start(); // 启动服务
		log.info("office转换服务启动成功!");
	} catch (Exception ce) {
		log.info("office转换服务启动失败!详细信息:" + ce);
	}
}
 
Example 9
Source File: WebappContext.java    From kbase-doc with Apache License 2.0 5 votes vote down vote up
public WebappContext(ServletContext servletContext, OpenOffice openOffice) {
	DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
	fileUpload = new ServletFileUpload(fileItemFactory);
	if (openOffice.getFileSizeMax() != null) {
		fileUpload.setFileSizeMax(Integer.parseInt(openOffice.getFileSizeMax()));
		logger.info("max file upload size set to " + openOffice.getFileSizeMax());
	} else {
		logger.warn("max file upload size not set");
	}
	
	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	if (openOffice.getPort() != null) {
		String ports = openOffice.getPort();
		String[] portArr = ports.split(",");
		int[] portArrInt = new int[portArr.length];
		int i = 0;
		for (String port : portArr){
			portArrInt[i++] = Integer.parseInt(port);
		}
	    configuration.setPortNumbers(portArrInt);
	}
	if (openOffice.getHome() != null) {
	    configuration.setOfficeHome(new File(openOffice.getHome()));
	}
	if (StringUtils.isNotBlank(openOffice.getProfile())) {
	    configuration.setTemplateProfileDir(new File(openOffice.getProfile()));
	}

	officeManager = configuration.buildOfficeManager();
	documentConverter = new OfficeDocumentConverter(officeManager);
}
 
Example 10
Source File: OfficePDFConverter.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
public static void startService(){  
    DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();  
    try {
    	System.out.println("准备启动服务....");
        configuration.setOfficeHome(OPEN_OFFICE_HOME);//设置安装目录  
        configuration.setPortNumbers(OPEN_OFFICE_PORT); //设置端口  
        configuration.setTaskExecutionTimeout(1000 * 60 * 5L);  
        configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);  
        officeManager = configuration.buildOfficeManager();  
        officeManager.start();    //启动服务  
        System.out.println("office转换服务启动成功!");
    } catch (Exception ce) {  
        System.out.println("office转换服务启动失败!详细信息:" + ce);  
    }  
}
 
Example 11
Source File: Doc2DocxUtil.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
public static void startService(){  
    DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();  
    try {  
        configuration.setOfficeHome(OPEN_OFFICE_HOME);//设置安装目录  
        configuration.setPortNumbers(OPEN_OFFICE_PORT); //设置端口  
        configuration.setTaskExecutionTimeout(1000 * 60 * 5L);  
        configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);  
        officeManager = configuration.buildOfficeManager();  
        officeManager.start();    //启动服务  
    } catch (Exception ce) {  
        System.out.println("office转换服务启动失败!详细信息:" + ce);  
    }  
}
 
Example 12
Source File: OfficeDocumentConvertServer.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
private void startService(String officeHome, int... ports) {
	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	try {
		System.out.println("准备启动office服务....");
		configuration.setOfficeHome(officeHome);// 设置安装目录
		configuration.setPortNumbers(ports); // 设置端口
		configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
		configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
		officeManager = configuration.buildOfficeManager();
		officeManager.start(); // 启动服务
		System.out.println("office转换服务启动成功!");
	} catch (Exception ce) {
		System.out.println("office转换服务启动失败!详细信息:" + ce);
	}
}
 
Example 13
Source File: ViewOfficeTools.java    From csustRepo with MIT License 5 votes vote down vote up
public synchronized OfficeManager newOfficeManager() {
	String officehome=ServletActionContext.getServletContext().getInitParameter("officehome");
	int portnumbers=Integer.parseInt(ServletActionContext.getServletContext().getInitParameter("portnumbers"));

	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	configuration.setOfficeHome(officehome);//设置OpenOffice.org安装目录
	configuration.setPortNumbers(portnumbers); //设置转换端口,默认为8100
	configuration.setTaskExecutionTimeout(1000 * 60 * 10L);//设置任务执行超时为5分钟
	configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);//设置任务队列超时为24小时
	
	return configuration.buildOfficeManager();
}
 
Example 14
Source File: ContextListener.java    From csustRepo with MIT License 5 votes vote down vote up
private void initViewOfficeTools(ServletContextEvent sce){

		String officehome=sce.getServletContext().getInitParameter("officehome");
		int portnumbers=Integer.parseInt(sce.getServletContext().getInitParameter("portnumbers"));

		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
		configuration.setOfficeHome(officehome);//设置OpenOffice.org安装目录
		configuration.setPortNumbers(portnumbers); //设置转换端口,默认为8100
		configuration.setTaskExecutionTimeout(1000 * 60 * 10L);//设置任务执行超时为5分钟
		configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);//设置任务队列超时为24小时

		OfficeManager officeManager=configuration.buildOfficeManager();
		officeManager.start();
		ViewOfficeTools.newInstance().setOfficeManager(officeManager);
	}