本文整理汇总了Java中org.artofsolving.jodconverter.OfficeDocumentConverter类的典型用法代码示例。如果您正苦于以下问题:Java OfficeDocumentConverter类的具体用法?Java OfficeDocumentConverter怎么用?Java OfficeDocumentConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OfficeDocumentConverter类属于org.artofsolving.jodconverter包,在下文中一共展示了OfficeDocumentConverter类的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();
}
}
示例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();
}
}
示例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());
}
}
示例4: OfficeConService
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
/**
*
* 创建一个新的实例 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);
}
示例5: startOpenOfficService
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
/**
* 启动转换服务
*/
public void startOpenOfficService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
LOGGER.info("==========>>> 开始启动 open office service 服务...");
configuration.setOfficeHome(openofficeHome);//设置OpenOffice.org安装目录
configuration.setPortNumbers(openofficePort); //设置转换端口,默认为8100
configuration.setTaskExecutionTimeout(1000 * 60 * 30L);//设置任务执行超时为5分钟
configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);//设置任务队列超时为24小时
officeManager = configuration.buildOfficeManager();
officeManager.start(); //启动服务
converter = new OfficeDocumentConverter(officeManager);
LOGGER.info("=========>>> open office service 服务已启动.");
startup = true;
} catch (Exception ce) {
ce.printStackTrace();
LOGGER.info("open office service 服务已启动失败!详细信息:" + ce);
stopOpenOfficService();
}
}
示例6: main
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
public static void main(String[] args) {
// 1) Start LibreOffice in headless mode.
OfficeManager officeManager = null;
try {
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(new File("C:/Program Files/LibreOffice 3.5"))
.buildOfficeManager();
officeManager.start();
// 2) Create JODConverter converter
OfficeDocumentConverter converter = new OfficeDocumentConverter(
officeManager);
// 3) Create PDF
createPDF(converter);
createPDF(converter);
} finally {
// 4) Stop LibreOffice in headless mode.
if (officeManager != null) {
officeManager.stop();
}
}
}
示例7: main
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
public static void main(String[] args) {
// 1) Start LibreOffice in headless mode.
OfficeManager officeManager = null;
try {
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(new File(Params.officeHome))
.buildOfficeManager();
officeManager.start();
// 2) Create JODConverter converter
OfficeDocumentConverter converter = new OfficeDocumentConverter(
officeManager);
// 3) Create HTML
createHTML(converter);
createHTML(converter);
} finally {
// 4) Stop LibreOffice in headless mode.
if (officeManager != null) {
officeManager.stop();
}
}
}
示例8: 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;
}
示例9: 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);
}
}
示例10: WebappContext
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
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);
}
示例11: 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);
}
示例12: 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转换服务完成。");
}
}
示例13: init
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
/**
* init method.
*/
public void init() {
ExternalOfficeManagerConfiguration externalProcessOfficeManager = new ExternalOfficeManagerConfiguration();
externalProcessOfficeManager.setPortNumber(serverPort);
externalProcessOfficeManager.setConnectOnStart(true);
this.jodOOManager = externalProcessOfficeManager.buildOfficeManager(server);
this.jodConverter = new OfficeDocumentConverter(this.jodOOManager);
}
示例14: doJodConvert
import org.artofsolving.jodconverter.OfficeDocumentConverter; //导入依赖的package包/类
/**
* Generates PDF using JOD Library (external library)
*
* @param in - file to convert
* @param out - file to write result
* @return - result of the conversion as {@link ProcessResult}
*/
public ProcessResult doJodConvert(File in, File out) {
try {
createOfficeManager(cfgDao.getString(CONFIG_PATH_OFFICE, null)
, man -> {
OfficeDocumentConverter converter = new OfficeDocumentConverter(man);
converter.convert(in, out);
});
} catch (Exception ex) {
log.error("doJodConvert", ex);
return new ProcessResult("doJodConvert", ex.getMessage(), ex);
}
return new ProcessResult("doJodConvert", "Document converted successfully", null)
.setExitCode(0);
}
示例15: 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();
}
}