我引用的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;
//去除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();
}