当前位置: 首页 > news >正文

网站挂黑链工具谷歌排名推广

网站挂黑链工具,谷歌排名推广,ecshop批发网站模板,山西省住房和建设厅网站描述 环境&#xff1a;docker 部署工具&#xff1a;Jenkins 需求&#xff1a;本地上传的word文档需要转换成pdf 问题&#xff1a;转换之后的pdf文档出现小框框&#xff08;乱码&#xff09; 转换成PDF的操作 pom&#xff1a; <dependency><groupId>org.apach…

描述

环境:docker

部署工具:Jenkins

需求:本地上传的word文档需要转换成pdf

问题:转换之后的pdf文档出现小框框(乱码)

转换成PDF的操作

pom:

        <dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.10.1</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>3.10.1</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.10.1</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.core</artifactId><version>1.0.6</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.pdf</artifactId><version>1.0.6</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>fr.opensagres.xdocreport.itext.extension</artifactId><version>2.0.1</version></dependency><dependency><groupId>com.luhuiguo</groupId><artifactId>aspose-words</artifactId><version>23.1</version></dependency>

License:

在resources文件夹下新增license.xml文件

复制粘贴下方代码:

<?xml version="1.0" encoding="UTF-8" ?>
<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>

Java代码:

import com.aspose.words.*;
import org.apache.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;import java.io.*;
import java.util.Objects;/*** word转pdf* @author Dr.Monster*/
public class Word2PdfUtil {public static void word2PdfPoi(String docFile,String pdfFile) {try{XWPFDocument document;InputStream doc = new FileInputStream(docFile);document = new XWPFDocument(doc);PdfOptions options = PdfOptions.create();OutputStream out = new FileOutputStream(pdfFile);PdfConverter.getInstance().convert(document, out, options);doc.close();out.close();}catch (Exception e){}}/*** 获取 license 去除水印* 若不验证则转化出的pdf文档会有水印产生*/private static void getLicense() {String licenseFilePath = "word-license.xml";try {InputStream is = Word2PdfUtil.class.getClassLoader().getResourceAsStream(licenseFilePath);License license = new License();license.setLicense(Objects.requireNonNull(is));} catch (Exception e) {e.printStackTrace();}}/*** word 转 pdf** @param wordFile word 文件路径* @param pdfFile  生成的 pdf 文件路径*/public static void word2Pdf(String wordFile, String pdfFile) {File file = new File(pdfFile);if (!file.getParentFile().exists()) {file.getParentFile().mkdir();}getLicense();try (FileOutputStream os = new FileOutputStream(new File(pdfFile))) {Document doc = new Document(wordFile);
//            FontSettings.getDefaultInstance().setFontsFolder("/usr/share/fonts/CN/fonts/Fonts" , true);FontSettings.getDefaultInstance().setFontsFolder("/var/fonts" , true);doc.save(os, SaveFormat.PDF);} catch (Exception e) {}}/*** word 转 pdf** @param wordFile word 文件流* @param pdfFile  生成的 pdf 文件流*/public static void word2Pdf(InputStream wordFile, OutputStream pdfFile) {getLicense();try {Document doc = new Document(wordFile);doc.save(pdfFile, SaveFormat.PDF);} catch (Exception e) {}}
}

调用方式:

Word2PdfUtil.word2Pdf("你的word文件路径和文件名" , "你的pdf文件路径和文件名");

出现的问题

word文档可以正常转换,本地文件转换显示正常,但是在服务上转换后,显示乱码,原因是没有对应字体。

解决方案:

1:复制windows上的字体

2:复制到/usr/share/fonts/CN/fonts/Fonts路径下(没有可以自己新增,理论上来说,任何地方都可以)

3:建立与容器与机器的文件映射关系,并在Jenkins中进行配置

-v /usr/share/fonts/CN/fonts/Fonts:/var/fonts

4:在代码中设置字体所在目录

FontSettings.getDefaultInstance().setFontsFolder("/var/fonts" , true);

注意,目录为容器中的挂载目录,不是机器的目录,通过容器中的地址,可以直接访问机器中对应映射关系的地址。

参考资料:

java将word转pdf_java word转pdf poi-CSDN博客

http://www.mmbaike.com/news/41323.html

相关文章:

  • 做可视化图表的网站昆明百度搜索排名优化
  • 基础做网站seo系统培训课程
  • 网站开发公司的推广费用推广营销方案
  • 想给孩子找点题做 都有什么网站百度账号购买网站
  • 网站 备案查询衡阳seo服务
  • go网站做富集分析大连谷歌seo
  • 免费网站转app地推项目对接平台
  • 有没有专门做针织衫的网站专业做网站官网
  • 上海有名的做网站的公司有哪些网络培训研修总结
  • 网站不想备案十大网站管理系统
  • 公司网站banner图尺寸seo难不难
  • 长春做网站优化价格今日新闻摘抄10条简短
  • photoshop电脑版怎么安装seo点击软件哪个好用
  • 安徽茶叶学会 网站建设拉人注册给佣金的app
  • 中山移动网站建设报价蜗牛精灵seo
  • 亚马逊官方网站怎么做杭州网站推广与优化
  • 做网站选哪家好谷歌app下载
  • 网站建设百度认证图片百度网址大全电脑版
  • 建立网站的技术路径google下载官网
  • 重庆企业的网站建设淘宝店铺如何推广
  • 做化妆刷的外贸网站关键词优化需要从哪些方面开展
  • 郑州百度网站推广h5网站制作平台
  • 个人网站如何赚钱常见的网络营销平台有哪些
  • 网站建设模版 优帮云站长工具中文精品
  • 微信公众号托管代运营公司排名seo
  • 响应式企业网站建设找谁做百度关键词排名
  • 香港特别行政区装饰网站建设简单网页制作成品和代码
  • 安全的营销型网站制作最近一周热点新闻
  • 微信二维码生成器合肥seo排名优化公司
  • 互联网官网嘉定区整站seo十大排名