当前位置: 首页>>代码示例>>Java>>正文


Java OfficeDocumentConverter.convert方法代码示例

本文整理汇总了Java中org.artofsolving.jodconverter.OfficeDocumentConverter.convert方法的典型用法代码示例。如果您正苦于以下问题:Java OfficeDocumentConverter.convert方法的具体用法?Java OfficeDocumentConverter.convert怎么用?Java OfficeDocumentConverter.convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.artofsolving.jodconverter.OfficeDocumentConverter的用法示例。


在下文中一共展示了OfficeDocumentConverter.convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConvert

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
@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();
        }
	}
 
开发者ID:ekoz,项目名称:kbase-doc,代码行数:26,代码来源:ConverteTests.java

示例2: convert

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private void convert(File inputFile, File outputFile){
		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
		configuration.setPortNumber(8100);
		configuration.setOfficeHome(new File("D:/Program Files/LibreOffice"));
//		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();
        }
	}
 
开发者ID:ekoz,项目名称:kbase-doc,代码行数:20,代码来源:ConverteTests.java

示例3: convert

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
/**
 * Convert a document format to another one.
 */
public void convert(File inputFile, String mimeType, File outputFile) throws ConversionException {
	log.debug("convert({}, {}, {})", new Object[]{inputFile, mimeType, outputFile});

	if (Config.SYSTEM_OPENOFFICE_PATH.equals("") && Config.SYSTEM_OPENOFFICE_SERVER.equals("")) {
		throw new ConversionException(Config.PROPERTY_SYSTEM_OPENOFFICE_PATH + " or " + Config.PROPERTY_SYSTEM_OPENOFFICE_SERVER
				+ " not configured");
	}

	if (!validOpenOffice.contains(mimeType)) {
		throw new ConversionException("Invalid document conversion MIME type: " + mimeType);
	}

	try {
		if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
			// Document conversion managed by local OO instance
			OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
			converter.convert(inputFile, outputFile);
		} else if (!Config.SYSTEM_OPENOFFICE_SERVER.equals("")) {
			// Document conversion managed by remote conversion server
			remoteConvert(Config.SYSTEM_OPENOFFICE_SERVER, inputFile, mimeType, outputFile, MimeTypeConfig.MIME_PDF);
		}
	} catch (OfficeException e) {
		throw new ConversionException("Error converting document: " + e.getMessage());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:29,代码来源:DocConverter.java

示例4: office2Pdf

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
public  boolean office2Pdf(String spath,String dpath){
	// 转换源文件
	File sourceFile = new File(spath);
	// PDF目标文件
	File pdfFile = new File(dpath);

	// swf文件名不能有中文或者特殊字符,否则会出现找不到文件路径的问题,并且文件名不能存在特殊字符(如%),否则转换会失败
	//	System.out.println("第一步:生成文件对象,准备转换");
	// 转换成pdf文件
	if (sourceFile.exists()) {
        OfficeDocumentConverter converter = 
        		new OfficeDocumentConverter(getOfficeManager());
        converter.convert(sourceFile,pdfFile);
	} else {
		//System.out.println("要转换的文件不存在");
		return false;
	}
	return true;		
}
 
开发者ID:binghuo365,项目名称:csustRepo,代码行数:20,代码来源:ViewOfficeTools.java

示例5: convertPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
@Override
public File convertPDF(File theFile, String md5UploadedFile) throws PDFConverterException {
	try {
		OfficeDocumentConverter converter = new OfficeDocumentConverter(AppContext.getOfficeManager());
		String outFileName = this.getOutputFileName(md5UploadedFile);
		File pdfOutput = new File(Config.getString("application.staticFiles"), outFileName);
		converter.convert(theFile, pdfOutput);
		return pdfOutput;
	} catch (Exception e) {
		log.error("Fail to create PDF in JOD Converter", e);
		log.info("Trying to restart office manager for next request...");
		AppContext.restartOfficeManager();
		throw new PDFConverterException("Fail to create PDF in JOD Converter", e);
	}
}
 
开发者ID:LeoFCardoso,项目名称:tudoToPDF,代码行数:16,代码来源:JODConverter.java

示例6: convert

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
@Override
protected void convert(File tempFromFile, DocumentFormat sourceFormat, File tempToFile,
        DocumentFormat targetFormat)
{
    OfficeDocumentConverter converter = new OfficeDocumentConverter(jodconverter.getOfficeManager());
    converter.convert(tempFromFile, tempToFile);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:8,代码来源:JodContentTransformer.java

示例7: office2pdf

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
/** 
 * 将Office文档转换为PDF. 需要安装OpenOffice
 *  
 * @param inputFilePath 
 *            源文件,绝对路径. 可以是Office2003-2007全部格式的文档, 包括.doc, .docx, .xls, .xlsx, .ppt, .pptx等. 
 *  
 * @param outputFilePath 
 *            目标文件.绝对路径. 
 */
public static void office2pdf(String inputFilePath, String outputFilePath) {
	DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();

	String officeHome = getOfficeHome();
	//设置OpenOffice.org安装目录
	config.setOfficeHome(officeHome);
	//设置转换端口,默认为8100
	//config.setPortNumbers(8100);  
	//设置任务执行超时为60分钟
	config.setTaskExecutionTimeout(1000 * 60 * 60L);
	//设置任务队列超时为24小时
	config.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
	OfficeManager officeManager = config.buildOfficeManager();
	officeManager.start();
	System.out.println("office转换服务启动成功!");
	OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
	File inputFile = new File(inputFilePath);
	if (inputFile.exists()) {// 找不到源文件, 则返回  
		File outputFile = new File(outputFilePath);
		if (!outputFile.getParentFile().exists()) { // 假如目标路径不存在, 则新建该路径  
			outputFile.getParentFile().mkdirs();
		}
		converter.convert(inputFile, outputFile);

	}
	if (null != officeManager) {
		officeManager.stop();
		System.out.println("office转换服务完成。");
	}
}
 
开发者ID:pecker,项目名称:kony-converter,代码行数:40,代码来源:OfficeToPdf.java

示例8: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/Docx4j_GettingStarted.docx"), new File(
				"pdf/Docx4j_GettingStarted.pdf"));
		System.err.println("Generate pdf/Docx4j_GettingStarted.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:Docx4j_GettingStartedToPDF.java

示例9: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/HelloWorld.docx"), new File(
				"pdf/HelloWorld.pdf"));
		System.err.println("Generate pdf/HelloWorld.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:HelloWorldToPDF.java

示例10: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/ooxml.docx"), new File(
				"pdf/ooxml.pdf"));
		System.err.println("Generate pdf/ooxml.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:ooxmlToPDF.java

示例11: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/Resume.docx"), new File(
				"pdf/Resume.pdf"));
		System.err.println("Generate pdf/Resume.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:ResumeToPDF.java

示例12: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/FormattingTests.docx"), new File(
				"pdf/FormattingTests.pdf"));
		System.err.println("Generate pdf/FormattingTests.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:FormattingTestsToPDF.java

示例13: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/TableWithRowsColsSpan.docx"), new File(
				"pdf/TableWithRowsColsSpan.pdf"));
		System.err.println("Generate pdf/TableWithRowsColsSpan.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:TableWithRowsColsSpanToPDF.java

示例14: createPDF

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createPDF(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/AdvancedTable.docx"), new File(
				"pdf/AdvancedTable.pdf"));
		System.err.println("Generate pdf/AdvancedTable.pdf with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:AdvancedTableToPDF.java

示例15: createHTML

import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入方法依赖的package包/类
private static void createHTML(OfficeDocumentConverter converter) {
	try {
		long start = System.currentTimeMillis();
		converter.convert(new File("docx/AdvancedTable.docx"), new File(
				"html/AdvancedTable.html"));
		System.err.println("Generate html/AdvancedTable.html with "
				+ (System.currentTimeMillis() - start) + "ms");
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
开发者ID:xxsafin,项目名称:DocToHtml,代码行数:12,代码来源:AdvancedTableToHTML.java


注:本文中的org.artofsolving.jodconverter.OfficeDocumentConverter.convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。