Evaluation Warning: The document was created with Spire.Doc for JAVA

我引用的jar包:poi-ooxml-3.17.jar maven仓库可下载
转换jar包:spire.doc-11.1.1.jar maven仓库可下载
去除Evaluation Warning: The document was created with Spire.Doc for JAVA亲测试可用
均可以去除WORD、PDF格式 源码在文章最后

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

源码如下:

//将html转换成word
//htmlPath html文件路径  
String htmlPath  = "html文件路径";
//wordPath word文件路径
String wordPath = "word文件路径";
//引用spire.doc-11.1.1.jar
Document doc = new Document();
doc.loadFromFile(htmlPath, FileFormat.Html, XHTMLValidationType.None);
//获取section
Section section = doc.getSections().get(0);
//设置word页边距  注:磅转厘米(CM)
section.getPageSetup().getMargins().setTop(102);
section.getPageSetup().getMargins().setBottom(102);
section.getPageSetup().getMargins().setLeft(77);
section.getPageSetup().getMargins().setRight(77);
//保存为Word格式到指定路径
doc.saveToFile(wordPath,FileFormat.Docx_2013);

去除水印 

//去除Evaluation Warning: The document was created with Spire.Doc for JAVA
try (FileInputStream in = new FileInputStream(wordPath)){
    XWPFDocument docnew = new XWPFDocument(OPCPackage.open(in));
    List<XWPFParagraph> paragraphs = docnew.getParagraphs();
    if (paragraphs.size() < 1){
        return true;
    }
    XWPFParagraph firstParagraph = paragraphs.get(0);
    if (firstParagraph.getText().contains("Spire.Doc")){
        docnew.removeBodyElement(docnew.getPosOfParagraph(firstParagraph));
    }
    OutputStream out = new FileOutputStream(wordPath);
    docnew.write(out);
    docnew.close();
} catch (Exception e) {
    e.printStackTrace();
}


                
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值