while(true): leaning()|

-Watcher-

园龄:2年11个月粉丝:0关注:0

openOffice 文档转换 部署

openOffice 文档转PDF

windows平台

下载地址: http://www.openoffice.org/zh-cn/download/

image-20220421235034943

安装-开启服务

进入安装目录 如:C:\Program Files (x86)\OpenOffice 4\program 执行命令

./soffice -accept="socket,host=0.0.0.0,port=8100,tcpNoDelay=1;urp;" -nofirststartwizard

端口监听命令

netstat -ano|findstr 8100

linux平台

下载

image-20220422140309979

上传 安装

1.解压 进入 zh-Ch 目录 ->RPMS 目录

tar -zxvf Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz
cd zh-Ch
cd RPMS

2.安装rpm 文件

rpm -ivh *.rpm

3.进入desktop-integration/目录

cd desktop-integration/

4.安装openoffice

rpm -ivh openoffice4.1.11-redhat-menus-4.1.11-9808.noarch.rpm

安装成功后会在/opt下出现一个openoffice4文件

image-20220422140816257

5.启动openofiice4 :

临时启动

/opt/openoffice4/program/soffice -headless -accept=“socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

后台启动

/opt/openoffice4/program/soffice -headless -accept="socket,host=0.0.0.0,port=8100;urp;" -nofirststartwizard &

服务器字体安装

1、安装字体库。

yum -y install fontconfig

安装完成后,在 /usr/share/ 目录下会新增 fonts 目录。

2、进入 fonst 目录在此新建一个chinese,导入字体文件。

mkdir chinses
chmod -R 755 /usr/share/fonts/chinses/

把自己Windows系统(C:\Windows\Fonts )中的相关字库添加至 /usr/share/fonts/chinses/ 下面!

cd /usr/share/fonts/chinses/

3、安装搜索目录字库。

yum -y install ttmkfdir

4、进入 fonts.conf 进行文件修改编辑。

vim /etc/fonts/fonts.conf
在<dir prefix="xdg">fonts</dir> 这一行下面加入:
<dir>/usr/share/fonts/chinese</dir>

5、建立字体缓存:

chmod -R 755 /usr/share/fonts/chinese/
cd /usr/share/fonts/chinese
mkfontscale (若提示 mkfontscale: command not found,需自行安装 # yum install mkfontscale )
mkfontdir(若提示 fc-cache: command not found,则需要安装# yum install fontconfig )
fc-cache -fv

最后再次通过fc-list看一下字体列表相关字体是否添加成功

注:重启用到字体库的服务,将字体库应用到服务中去

服务器转换服务

maven 依赖引入

<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>

工具类代码

package com.woma.utils;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
import java.io.File;
import java.io.FileNotFoundException;
//转换文档为pdf
public class OpenOfficePdfConvert {
/**
* @param args
*/
private static OfficeManager officeManager;
private static String OFFICE_HOME = "C:/Program Files (x86)/OpenOffice 4/";
private static int port[] = { 8100 };
public void convert2PDF(String inputFile, String outputFile) throws FileNotFoundException {
startService();
System.out.println("进行文档转换转换:" + inputFile + " --> " + outputFile);
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(new File(inputFile), new File(outputFile));
stopService();
System.out.println();
}
// 打开服务器
public static void startService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
System.out.println("准备启动服务....");
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(); // 启动服务
System.out.println("office转换服务启动成功!");
} catch (Exception ce) {
System.out.println("office转换服务启动失败!详细信息:" + ce);
}
}
// 关闭服务器
public static void stopService() {
System.out.println("关闭office转换服务....");
if (officeManager != null) {
officeManager.stop();
}
System.out.println("关闭office转换成功!");
}
public static void main(String[] args) throws Exception {
String path = "D:/Gongcheng/xiangmu/springbootDemo/download/";
OpenOfficePdfConvert opc = new OpenOfficePdfConvert();
opc.convert2PDF(path+"1.docx", path+"1.pdf");
}
}

使用方法

@Test
void demo2(){
String fromPath="D:/Gongcheng/xiangmu/springbootDemo/download/极简新中式PPT模板.ppt";
String toPath="D:/Gongcheng/xiangmu/springbootDemo/upload/";
OfficeToPDF officeToPDF = new OfficeToPDF();
officeToPDF.convert(fromPath,toPath,"极简新中式PPT模板");
}

本地转换服务(旧)

maven 依赖引入

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.github.livesense</groupId>
<artifactId>jodconverter-core</artifactId>
<version>1.0.5</version>
</dependency>

工具类代码

import java.io.File;
import java.io.FileNotFoundException;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
//转换文档为pdf
public class OpenOfficePdfConvert {
/**
* @param args
*/
private static OfficeManager officeManager;
private static String OFFICE_HOME = "C:/Program Files (x86)/OpenOffice 4/";
private static int port[] = { 8100 };
public void convert2PDF(String inputFile, String outputFile) throws FileNotFoundException {
startService();
System.out.println("进行文档转换转换:" + inputFile + " --> " + outputFile);
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(new File(inputFile), new File(outputFile));
stopService();
System.out.println();
}
// 打开服务器
public static void startService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
System.out.println("准备启动服务....");
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(); // 启动服务
System.out.println("office转换服务启动成功!");
} catch (Exception ce) {
System.out.println("office转换服务启动失败!详细信息:" + ce);
}
}
// 关闭服务器
public static void stopService() {
System.out.println("关闭office转换服务....");
if (officeManager != null) {
officeManager.stop();
}
System.out.println("关闭office转换成功!");
}
//启动方法
public static void main(String[] args) throws Exception {
String path = "C:/Users/johnny/Desktop/文档/20170420/test/001/";
OpenOfficePdfConvert opc = new OpenOfficePdfConvert();
opc.convert2PDF(path+"1.docx", path+"1.pdf");
}
}

使用方法

@Test
void demo() throws FileNotFoundException {
String path = "D:/Gongcheng/xiangmu/springbootDemo/download/";
OpenOfficePdfConvert opc = new OpenOfficePdfConvert();
opc.convert2PDF(path+"黑白几何体.pptx", path+"黑白几何体.pdf");
}

本文作者:-Watcher-

本文链接:https://www.cnblogs.com/womaspace/p/18635408

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   -Watcher-  阅读(14)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found Radical Face
404 not found - Radical Face
00:00 / 00:00
An audio error has occurred.

Welcome Home - Radical Face

Written by:Ben P. Cooper

Sleep don't visit so I choke on sun

And the days blur into one

And the backs of my eyes hum with things

I've never done

Sheets are swaying from an old clothesline

Like a row of captured ghosts over old dead grass

Was never much but we made the most

Welcome home

Ships are launching from my chest

Some have names but most do not

You find If one

Please let me know what piece I've lost

Heal the scars from off my back

I don't need them anymore

You can throw them out or

Keep them in your mason jars

I've come home

All my nightmares escaped my head

Bar the door please don't let them in

You were never supposed to leave

Now my head's splitting at the seams

And I don't know if I can

Here beneath my lungs

I feel your thumbs press into my skin again