docx4j操作word(3)

2019-08-20 19:58

/* * block.setSectionBreakBefore(SectionBreakBefore.NONE); //block.setFooterBehaviour(footerBehaviour); // * if you want no headers on the pages from docx2: block.setHeaderBehaviour(HfBehaviour.DEFAULT); */ block.setSectionBreakBefore(SectionBreakBefore.NONE); block.setStyleHandler(StyleHandler.RENAME_RETAIN); block.setNumberingHandler(NumberingHandler.ADD_NEW_LIST); block.setRestartPageNumbering(false); block.setHeaderBehaviour(HfBehaviour.DEFAULT); block.setFooterBehaviour(HfBehaviour.DEFAULT); } DocumentBuilderdocumentBuilder = newDocumentBuilder(); // Use macros from the first block range documentBuilder.setRetainMacros(blockRanges.get(0)); // Perform the actual merge target = documentBuilder.buildOpenDocument(blockRanges); MainDocumentPartmain = target.getMainDocumentPart(); List

list = newArrayList<>(); main.getContent().forEach((obj) -> { if (obj.toString().indexOf(\Docx4j\) >= 0) { P p = (P) obj; list.add(p); } }); list.forEach((p) -> { main.getContent().remove(p); }); } catch (Exception e) { e.printStackTrace(); } returntarget; } 企业版的下载地址

http://www.plutext.com/m/index.php/products?_ga=1.209329106.1555965705.1478829970

3.2. word转换成pdf

word转换成PDF,其他的方法转换都有乱码问题、chart无法转换等。可以使用documents4j,http://documents4j.com/, 如果服务器在linux上,那么可以使用服务的方式,进行调用。 @Override publicvoidconvert(File file, File dest, IConvertFileConsumerconsumer, FileTypetype) throws Exception { IConverterconverter = RemoteConverter.builder().baseFolder(new File(\)) .workerPool(20, 25, 2, TimeUnit.SECONDS).requestTimeout(11, TimeUnit.SECONDS) .baseUri(\).build(); if (type.equals(FileType.PDF)) { converter.convert(file).as(DocumentType.DOCX).to(dest, newIFileConsumer() { @Override publicvoidonException(File file, Exception e) { } @Override publicvoidonComplete(File file) { consumer.accept(file); } @Override publicvoidonCancel(File file) { } }).as(DocumentType.PDF).execute(); } }


docx4j操作word(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:测试用例(Test Case)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: