[Original] java operation word to generate watermark

Application scenarios

         In order to protect the copyright or identify the authenticity of the file, sometimes it is necessary to dynamically add a watermark to the generated Word file. The WaterMark class of the PageOffice component encapsulates the function of adding a watermark to the online edited Word file, and the calling interface is very simple.

The namespace to which the WaterMark class belongs

         com.zhuozhengsoft.pageoffice.wordwriter

Supports two watermarks

  Insert text watermark (core code):

1      WordDocument doc = new WordDocument();
 2      // Add a watermark, the parameter in the setText(String) method is the content of the watermark to be added 
3      doc.getWaterMark().setText("PageOffice Development Platform" );
 4      poCtrl1.setWriter (doc); // don't forget this sentence

  Text watermark effect:

  

  Insert image watermark (core code):

1       WordDocument doc = new WordDocument();
 2       // Add a watermark, the parameter in the setImage(String) method is the url address of the watermark image to be added 
3       doc.getWaterMark().setImage("images/logo.png" );
 4       poCtrl1.setWriter(doc); // Don't forget this sentence

   Image watermark effect:

  

Source code download

  Visit: http://www.zhuozhengsoft.com/dowm/, download PageOffice for Java, after decompression, copy the Samples4 folder to the Webapps directory of Tomcat, visit: http://localhost:8080/Samples4/index.html, View the example: 2. 9. Add a watermark to a Word document

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325793119&siteId=291194637