# office2pdf **Repository Path**: 1051793673/office2pdf ## Basic Information - **Project Name**: office2pdf - **Description**: office转pdf,支持openoffice 或 liebreoffice 转 pdf、html等 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2022-05-11 - **Last Updated**: 2022-07-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### DynamicOffice2Pdf 配置 ``` springboot项目中配置文件application.yml或application.properties增加配置 office: home: dir: D:\Program Files\openoffice 4 out: dir: D:\out\ convert: host: 127.0.0.1 linux环境 office: home: dir: /opt/openoffice4/ out: dir: /out/ convert: host: 127.0.0.1 ``` ```` 说明: office.home.dir: openoffice或libreoffice 安装目录 office.out.dir: openoffice或libreoffice 转换后输出目录 office.convert.host: openoffice或libreoffice的服务ip,不配置就是默认当前服务器 ```` #### 这里以 openoffice 部署为例 #### centos 离线部署 openoffice ``` openoffice下载地址: http://www.openoffice.org/download/ 如: Apache_OpenOffice_4.1.10_Linux_x86-64_install-rpm_zh-CN.tar.gz 部署脚本 install.sh: #!/bin/sh tar -zxvf Apache_OpenOffice_4.1.10_Linux_x86-64_install-rpm_zh-CN.tar.gz cd zh-CN/RPMS yum localinstall *.rpm cd desktop-integration/ yum localinstall openoffice4.1.10-redhat-menus-4.1.10-9807.noarch.rpm ``` #### 项目pull后,编译并deploy到私服 #### pom引入使用 ``` com.lixy office2pdf-spring-boot-starter 0.0.1-snapshots ``` #### DynamicOffice2Pdf 使用 ``` 直接注入使用: @Autowired private DynamicOffice2Pdf dynamicOffice2Pdf; //返回转换后文件路径 String localPdfFile = dynamicOffice2Pdf.convert(convertVo.getToConvertPath()); //输入也可是流,并指定输出文件名,如下 convert(InputStream in, String fileName) ``` #### StaticOffice2Pdf ````StaticOffice2Pdf 文件转换需要提前设置office home和输出目录```` ### deploy到nexus需要配置 pom.xml和setting.xml ``` 详情查看 pom.xml中distributionManagement的repository 和 setting.xml文件 ``` #### centos 文件转换乱码处理 ``` 将 window上的字体(主要是simhei.ttf和simsun.ttc) 拷贝到 centos上的 /usr/share/fonts 参考:https://www.pianshen.com/article/70001186547/ 如果还是不行,增加jdk的字体 参考:https://www.vultrer.com/207.html ``` #### 对于项目采用docker部署的情况,需要对字体文件和转换目录进行挂载 ```如 docker-compose.yml 文件中挂载了 openoffice文件安装目录和转换输出目录及字体目录 - /opt/openoffice4/:/opt/openoffice4/ - ./out/:/out/ - /usr/share/fonts:/usr/share/fonts ``` #### docker 安装部署nexus ``` 参考:https://blog.csdn.net/EasternUnbeaten/article/details/91047715 启动时指定容器目录: docker run -d --name nexus3 \ --restart=always \ -p 8081:8081 \ -p 8082:8082 \ -v /nexus-data:/nexus-data \ sonatype/nexus3 需要给/nexus-data 目录赋权限 chmod 777 /nexus-data ```