IDEA中怎么设置项目更改后的分析延迟时间,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置项目更改后的分析延迟时间,这样就可确保项目范围分析的正确性,具体的操作步骤如下。......
2023-07-04 619 JAVA
Word中设置水印时,可预设的文字或自定义文字设置为水印效果,但通常添加水印效果时,会对所有页面都设置成统一效果,如果需要对每一页或者某个页面设置不同的水印效果,则可以参考下面的方法。
将Word库下载到本地,并解压,找到lib文件夹下的jar文件。然后在IDEA程序中打开“Project Structure”,执行如图步骤:
找到本地路径下的jar文件,点击“OK”,添加到列表:
勾选选项,点击“Apply”,然后等待程序安装导入jar:
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;
public class DifferentTextWatermark {
public static void main(String[] args) {
//加载Word测试文档
Document doc = new Document();
doc.loadFromFile("test.docx");
//获取文档第一节
Section section1 = doc.getSections().get(0);
//定义水印文字的纵向坐标位置
float y = (float) (section1.getPageSetup().getPageSize().getHeight()/3);
//添加文字水印1
HeaderFooter header1 = section1.getHeadersFooters().getHeader();//获取页眉
header1.getParagraphs().clear();//删除原有页眉格式的段落
Paragraph para1= header1.addParagraph();//重新添加段落
//添加艺术字并设置大小
ShapeObject shape1 = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape1.setWidth(362);
shape1.setHeight(118);
//设置艺术字文本内容、位置及样式(即文本水印字样)
shape1.setRotation(315);
shape1.getWordArt().setText("内部使用");
shape1.setFillColor(new Color(128,128,128));
shape1.setLineStyle(ShapeLineStyle.Single);
shape1.setStrokeColor(new Color(128,128,128));
shape1.setStrokeWeight(0.5);
shape1.setVerticalPosition(y);
shape1.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
para1.getChildObjects().add(shape1);
//同理设置第二节页眉中的文字水印2
Section section2 = doc.getSections().get(1);
HeaderFooter header2 = section2.getHeadersFooters().getHeader();
header2.getParagraphs().clear();
Paragraph para2= header2.addParagraph();
ShapeObject shape2 = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape2.setWidth(362);
shape2.setHeight(118);
shape2.setRotation(315);
shape2.getWordArt().setText("绝密资料");
shape2.setFillColor(new Color(221,160,221));
shape2.setLineStyle(ShapeLineStyle.Single);
shape2.setStrokeColor(new Color(221,160,221));
shape2.setStrokeWeight(0.5);
shape2.setVerticalPosition(y);
shape2.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
para2.getChildObjects().add(shape2);
//同理设置第三节中的页眉中的文字水印3
Section section3 = doc.getSections().get(2);
HeaderFooter header3 = section3.getHeadersFooters().getHeader();
header3.getParagraphs().clear();
Paragraph para3= header3.addParagraph();
ShapeObject shape3 = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape3.setWidth(362);
shape3.setHeight(118);
shape3.setRotation(315);
shape3.getWordArt().setText("禁止传阅");
shape3.setFillColor(new Color(70,130,180));
shape3.setLineStyle(ShapeLineStyle.Single);
shape3.setStrokeColor(new Color(70,130,180));
shape3.setStrokeWeight(0.5);
shape3.setVerticalPosition(y);
shape3.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
para3.getChildObjects().add(shape3);
//保存文档
doc.saveToFile("DifferentTextWatermark.docx",FileFormat.Docx_2013);
doc.dispose();
}
}
执行代码后,生成的Word文档中,可查看每一页的文字水印效果,如图:
以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!
相关文章
IDEA中怎么设置项目更改后的分析延迟时间,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置项目更改后的分析延迟时间,这样就可确保项目范围分析的正确性,具体的操作步骤如下。......
2023-07-04 619 JAVA
IDEA中怎么设置调试器最近表达式的最大数量,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置调试器最近表达式的最大数量,从而有效避免调试器中表达式存储过多。......
2023-07-04 440 JAVA