ireport 如何设置水印或者背景?

czp3158 2011-05-13 11:31:14
网上找了下好像设不了啊~ 现在客户要求做咋办呀~
...全文
462 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
http://download.csdn.net/source/676114
NickCheng 2011-05-13
  • 打赏
  • 举报
回复
http://www.finereport.com

放在 summary 里面就可以了!

指定一个区域,设定背景色,可以达到效果


package pdf;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfGState;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class PDFProcessor {

public static void main(String[] args) throws DocumentException, IOException {
Rectangle rectPageSize = new Rectangle(PageSize.A4); // 定义A4页面格式
Document doc = null;
doc = new Document(rectPageSize);

// response.setContentType("application/pdf");
// PdfWriter pw = PdfWriter.getInstance(doc,
// response.getOutputStream());
PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream(new File("d:\\test.pdf"))); //作为临时文件写到硬盘上

doc.open();

// 加入标题
String headString = "标题";
PdfParagraph headTitle = new PdfParagraph(headString, 16, true);
headTitle.setAlignment(1); // 1,居中 2,居右 3,局左
headTitle.setSpacingBefore(10); // 设置前面的空格数
headTitle.setSpacingAfter(10); // 设置跟后面的表格之间的空格数
doc.add(headTitle);// 加入标题

// 表格内容
PdfPTable table = new PdfPTable(1);// 设置最外边表的列数,1列
table.setWidthPercentage(90);// 设置最外边表的宽度

PdfPCell firstTableCell = new PdfPCell();
firstTableCell.addElement(new Paragraph());
table.addCell(firstTableCell);

doc.add(table);// 文档把最外边的表格加入

/*-----加入水印 start------------*/

PdfContentByte dc = pw.getDirectContent();
// PdfContentByte dcu = pw.getDirectContentUnder();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,BaseFont.EMBEDDED);
dc.beginText();
dc.setFontAndSize(bf, 32);
dc.setColorFill(new Color(0xFE, 0xA0, 0xA0));
PdfGState gs2 = new PdfGState();
gs2.setFillOpacity(0.5f);
dc.setGState(gs2);

dc.showTextAligned(Element.ALIGN_LEFT, "waterTitle", 110, 430, 30);//水印的文字,不能用中文
dc.endText();
/*-----加入水印 end------------*/
dc.showText("asdfsadfsdfsdfsdfsadfsdfasd");

//PdfImage img= new PdfImage()

pw.flush();
doc.close();
pw.close();

}

}

shadow4222 2011-05-13
  • 打赏
  • 举报
回复
同求帮顶
顺便问下2L ireport怎么弄背景图

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧