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

泰安可靠的网站建设天津建站网

泰安可靠的网站建设,天津建站网,企业网站模板 下载 免费,官方网站打不开怎么回事一、免费方式 优点:1、免费;2、在众多免费中挑选出的转换效果相对较好,并且不用像openOffice那样安装服务 缺点:1、对字体支持没有很好,需要安装字体库或者使用宋体(对宋体支持很好)2、对于使…

一、免费方式

优点:1、免费;2、在众多免费中挑选出的转换效果相对较好,并且不用像openOffice那样安装服务

缺点:1、对字体支持没有很好,需要安装字体库或者使用宋体(对宋体支持很好)2、对于使用freeMarker模板转化过来的doc无法读取转换

第一步:

        <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId><version>2.0.1</version></dependency>

第二步:

public static void main(String[] args) throws Exception {FileInputStream fileInputStream = new FileInputStream("D:\\test\\研判报告docx.docx");XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream);
// 将word中字体转化为宋体,防止其他字体无法正常显示setFontType(xwpfDocument);FileOutputStream fileOutputStream = new FileOutputStream("D:\\test\\研判报告11.docx");PdfConverter.getInstance().convert(xwpfDocument,fileOutputStream,pdfOptions);fileInputStream.close();fileOutputStream.close();}/**** 将文档的文字设置为宋体 防止其他字体转pdf不显示* @Description:* @param xwpfDocument* @return:*/private static void setFontType(XWPFDocument xwpfDocument) {//转换文档中文字字体List<XWPFParagraph> paragraphs = xwpfDocument.getParagraphs();if(paragraphs != null && paragraphs.size()>0){for (XWPFParagraph paragraph : paragraphs) {List<XWPFRun> runs = paragraph.getRuns();if(runs !=null && runs.size()>0){for (XWPFRun run : runs) {run.setFontFamily("宋体");}}}}//转换表格里的字体 我也不想俄罗斯套娃但是不套真不能设置字体List<XWPFTable> tables = xwpfDocument.getTables();for (XWPFTable table : tables) {List<XWPFTableRow> rows = table.getRows();for (XWPFTableRow row : rows) {List<XWPFTableCell> tableCells = row.getTableCells();for (XWPFTableCell tableCell : tableCells) {List<XWPFParagraph> paragraphs1 = tableCell.getParagraphs();for (XWPFParagraph xwpfParagraph : paragraphs1) {List<XWPFRun> runs = xwpfParagraph.getRuns();for (XWPFRun run : runs) {run.setFontFamily("宋体");}}}}}}

二、收费方式:

除了收费没啥缺点

1、freemarker生成word模板

①、自己新建一个word文档,内容就按照需要的格式内容

②、word文档另存为,选择xml格式

③、修改xml后缀为ftl放在如图位置

 ④代码:

    public static void main(String[] args) throws Exception {//1.创建配置类Configuration configuration=new Configuration(Configuration.getVersion());//2.设置模板所在的目录configuration.setDirectoryForTemplateLoading(new File(".\\template"));//3.设置字符集configuration.setDefaultEncoding("utf-8");//4.加载模板Template template = configuration.getTemplate("研判报告docx.ftl");//5.创建数据模型Map map=new HashMap();map.put("name","姓名姓名");map.put("idCard","身份证号码");map.put("age","36");map.put("sex","男");Map<String, Object> data1 = new HashMap<>();data1.put("item",map);Writer out =new FileWriter(new File(".\\template\\研判报告docx.docx"));//7.输出template.process(data1, out);//8.关闭Writer对象out.close();}

2、word转pdf

①、新建asposeLicense.xml放到如图位置

 asposeLicense.xml内容:

<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>

②、代码

public static void main(String[] args) {String docPath = ".\\template\\研判报告docx.docx";String savePath = ".\\template\\研判报告docx4.pdf";word2pdf(docPath, savePath);}public static void word2pdf(String docPath, String savePath) {try {ClassPathResource resource = new ClassPathResource("asposeLicense.xml");InputStream inputStream = resource.getInputStream();License license = new License();license.setLicense(inputStream);com.aspose.words.Document document = new com.aspose.words.Document(docPath);document.save(new FileOutputStream(new File(savePath)), SaveFormat.PDF);} catch (Exception e) {e.printStackTrace();}}

http://www.zhongyajixie.com/news/22691.html

相关文章:

  • 为客户做网站的方案互联网广告联盟
  • 北京好的网站建设公司百度客服怎么转人工
  • 惠州禅城网站建设郑州seo优化外包顾问
  • 北京有哪些炫酷的网站页面秦皇岛seo招聘
  • 做思维导图的在线网站北京seo培训
  • 一个网站如何做盈利网销是做什么的
  • 有没有什么网站做卷子重要新闻
  • 域名申请了怎么做网站搜索引擎有哪几个网站
  • ppt模板制作免费下载seo优化seo外包
  • 织梦绑定网站出现错误产品推广运营的公司
  • 北京网站建设制作案例徐州seo建站
  • dw里响应式网站怎么做成都网络营销公司哪家好
  • 深圳的网站建设公司电话百度后台推广登录
  • 江油网站建设靠谱seo整站优化外包
  • 电商网站商品表设计长春网站制作计划
  • 做网站名 注册那个商标seo技术专员招聘
  • 做网站需要学会些什么软件安卓优化大师全部版本
  • 电子商务网站建设如何实施论坛外链代发
  • 如何建网站教程百度云服务器
  • 旅游网站建设规模网络营销策略实施的步骤
  • 蓝色网站配色推广引流吸引人的标题
  • 阜阳市住房和城乡建设部网站刚刚中国出啥大事了
  • 免费商城网站源码百度号码认证平台
  • 做徒步网站怎么样营销型网站推广
  • 做网站还需要搜狗吗电商运营的基本流程
  • 做照片书哪个网站好手机系统优化软件
  • 网站开发策略都有啥seo推广沧州公司电话
  • html5做的篮球网站网络营销做得好的企业有哪些
  • 海南省建设网站首页竞价代运营公司
  • 网站开发需求表网站的优化公司