本文整理汇总了Java中org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java DefaultOfficeManagerConfiguration类的具体用法?Java DefaultOfficeManagerConfiguration怎么用?Java DefaultOfficeManagerConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultOfficeManagerConfiguration类属于org.artofsolving.jodconverter.office包,在下文中一共展示了DefaultOfficeManagerConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvert
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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.office.DefaultOfficeManagerConfiguration; //导入依赖的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: OfficeConService
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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);
}
示例4: startOpenOfficService
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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();
}
}
示例5: main
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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();
}
}
}
示例6: main
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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();
}
}
}
示例7: startService
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
private void startService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
LOG.info("start service....");
configuration.setOfficeHome(OFFICE_HOME);// 设置OpenOffice.org安装目录
configuration.setPortNumbers(port); // 设置转换端口,默认为8100
configuration.setTaskExecutionTimeout(1000 * 60 * 5L);// 设置任务执行超时为5分钟
configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);// 设置任务队列超时为24小时
officeManager = configuration.buildOfficeManager();
officeManager.start(); // 启动服务
LOG.info("office converting service start successfully");
} catch (Exception e) {
LOG.error("fail to start converting service", e);
}
}
示例8: createOfficeManager
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
public static void createOfficeManager(String officePath, Consumer<OfficeManager> consumer) {
OfficeManager manager = null;
try {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
if (!Strings.isEmpty(officePath)) {
configuration.setOfficeHome(officePath);
}
manager = configuration.buildOfficeManager();
manager.start();
if (consumer != null) {
consumer.accept(manager);
}
} finally {
if (manager != null) {
manager.stop();
}
}
}
示例9: buildJODConfiguration
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
private static void buildJODConfiguration() {
configuration = new DefaultOfficeManagerConfiguration();
int[] officePortParam = Config.getIntArray("jod.port");
if (officePortParam != null) {
configuration.setPortNumbers(officePortParam);
}
String officeHomeParam = Config.getString("jod.home");
if (officeHomeParam != null) {
configuration.setOfficeHome(new File(officeHomeParam));
}
String officeProfileParam = Config.getString("jod.profile");
if (officeProfileParam != null) {
configuration.setTemplateProfileDir(new File(officeProfileParam));
}
Long timeoutParam = Config.getLong("jod.timeoutMillis");
if (timeoutParam != null) {
configuration.setTaskExecutionTimeout(timeoutParam);
}
//TODO - test!
configuration.setMaxTasksPerProcess(1);
}
示例10: initialize
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
public static void initialize(List<Long> listenAtPorts) {
if(null == officeManager) {
OpenOfficeConfig.setPorts(listenAtPorts);
int[] ports = OpenOfficeConfig.getPorts();
Logger.getLogger(OpenOfficeService.class.getName()).log(Level.INFO,
"Initializing OfficeManager in ports: "+Arrays.toString(ports));
//OS X: cd /Applications/LibreOffice.app/Contents/MacOS/
// sudo ln -s ./soffice soffice.bin
// FIXED in master:
// https://github.com/nuxeo/jodconverter/commit/30eb0644a217081ce936a866ac6be411c62c6f49
officeManager = new DefaultOfficeManagerConfiguration().
setPortNumbers(ports).
buildOfficeManager();
} else {
Logger.getLogger(OpenOfficeService.class.getName()).log(Level.WARNING,
"OfficeManager is already initialized!");
}
}
示例11: WebappContext
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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);
}
示例12: init
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
@PostConstruct
private void init() {
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(new File(officeConfig.getOfficeHome()))
.setPortNumber(officeConfig.getOfficePort())
.buildOfficeManager();
officeManager.start();
}
示例13: getInstance
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
/**
* Retrieve class instance
*/
public static synchronized DocConverter getInstance() {
if (instance == null) {
instance = new DocConverter();
if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
log.info("*** Build Office Manager ***");
log.info("{}={}", Config.PROPERTY_SYSTEM_OPENOFFICE_PATH, Config.SYSTEM_OPENOFFICE_PATH);
log.info("{}={}", Config.PROPERTY_SYSTEM_OPENOFFICE_TASKS, Config.SYSTEM_OPENOFFICE_TASKS);
log.info("{}={}", Config.PROPERTY_SYSTEM_OPENOFFICE_PORT, Config.SYSTEM_OPENOFFICE_PORT);
officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome(Config.SYSTEM_OPENOFFICE_PATH)
.setMaxTasksPerProcess(Config.SYSTEM_OPENOFFICE_TASKS).setPortNumber(Config.SYSTEM_OPENOFFICE_PORT)
.buildOfficeManager();
} else {
log.warn("{} not configured", Config.PROPERTY_SYSTEM_OPENOFFICE_PATH);
if (!Config.SYSTEM_OPENOFFICE_SERVER.equals("")) {
log.warn("but {} is configured", Config.PROPERTY_SYSTEM_OPENOFFICE_SERVER);
log.info("{}={}", Config.PROPERTY_SYSTEM_OPENOFFICE_SERVER, Config.SYSTEM_OPENOFFICE_SERVER);
} else {
log.warn("and also {} not configured", Config.PROPERTY_SYSTEM_OPENOFFICE_SERVER);
}
}
}
return instance;
}
示例14: office2pdf
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的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转换服务完成。");
}
}
示例15: startOManager
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; //导入依赖的package包/类
private synchronized OfficeManager startOManager() throws Exception
{
String officeHome = EnvironmentConfig.getOpenOfficeHomePath();
if (officeHome == null || officeHome.trim().equals(""))
throw new Exception("OpenOfficeHomePath EnvironmentConfig must be set!");
OfficeManager officeManager = null;
long start = 0;
long end = 0;
int port = getAvaiblePort();
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(officeHome)
.setConnectionProtocol(OfficeConnectionProtocol.SOCKET)
.setPortNumber(port)
.setTaskExecutionTimeout(taskExecutionTimeout)
.setMaxTasksPerProcess(maxTasksPerProcess)
.buildOfficeManager();
System.out.println("OfficeHome : " + officeHome);
start = System.currentTimeMillis();
/**************************************************************/
try {
officeManager.start();
}
catch (Exception exception) {
throw new Exception("OfficeManager start failed: ", exception);
}
/**************************************************************/
end = System.currentTimeMillis();
System.out.println("Starting time : " + (new Float(end-start))/1000 + " seconds");
return officeManager;
}