Spire.doc jar包实现word文件添加水印demo

/**
 * @create: 2020-02-23 21:50
 */
import com.spire.doc.*;
import com.spire.doc.documents.WatermarkLayout;

import java.awt.*;


public class Main {
    public static void main(String[] args) {

     String inputFile="H:\\watermarkTemplate.doc";
     String outputFile="G:\\textWaterMark.docx";

     //open a Word document as template
     Document document = new Document(inputFile);

     //insert text watermark
     insertTextWatermark(document.getSections().get(0));

     //save to file
     document.saveToFile(outputFile, FileFormat.Docx);
    }
     private static void insertTextWatermark(Section section) {
      TextWatermark txtWatermark = new TextWatermark();
      txtWatermark.setText("yxf");
      txtWatermark.setFontSize(95);
      txtWatermark.setColor(Color.red);
      txtWatermark.setLayout(WatermarkLayout.Diagonal);
      section.getDocument().setWatermark(txtWatermark);
     }
 }

 

注意:office 2007 正常  office 2003 显示不出来

Spire.Doc.jar   百度云下载

链接:https://pan.baidu.com/s/1nYQe7dkqiqkuPCC68mrMJg
提取码:3rr9

 

 

上一篇:Spire.Cloud 私有化部署教程(二)- Ubuntu 18.04 系统


下一篇:PKUWC/SC 做题笔记