itext生成重复水印(watermark)
编程技术  /  houtizong 发布于 3年前   319
writer.setPageEvent(new Watermark("HELLO WORLD"));//水印内容//在继承自PdfPageEventHelper类中的OnEndPage方法中添加水印public void OnEndPage(PdfWriter writer, Document document) {ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_RIGHT, header[0], 100.0f, 200.0f, 0);}
That method is obsolete. Use page events to add watermarks (as many as you want). br, Bruno
showTextAlignedpublic static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation)Shows a line of text. Only the first line is written. Parameters:canvas - where the text is to be written toalignment - the alignmentphrase - the Phrase with the textx - the x reference positiony - the y reference positionrotation - the rotation to be applied in degrees counterclockwise
public class Watermark extends PdfPageEventHelper {Font FONT = new Font(FontFamily.HELVETICA, 30, Font.BOLD, new GrayColor(0.95f));private String waterCont;//水印内容public Watermark() {}public Watermark(String waterCont) {this.waterCont = waterCont;}@Overridepublic void onEndPage(PdfWriter writer, Document document) {for(int i=0 ; i<5; i++) {for(int j=0; j<5; j++) {ColumnText.showTextAligned(writer.getDirectContentUnder(), Element.ALIGN_CENTER, new Phrase(this.waterCont == null ? "HELLO WORLD" : this.waterCont, FONT), (50.5f+i*350), (40.0f+j*150), writer.getPageNumber() % 2 == 1 ? 45 : -45);}}}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接