首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

Struts2顶用itext实现PDF文件导出

2012-11-09 
Struts2中用itext实现PDF文件导出先看struts2配置文件:再看action类:import com.lowagie.text.Documentim

Struts2中用itext实现PDF文件导出
先看struts2配置文件:



再看action类:

import com.lowagie.text.Document;import com.lowagie.text.Font;import com.lowagie.text.Paragraph;import com.lowagie.text.pdf.BaseFont;import com.lowagie.text.pdf.PdfWriter;private InputStream pdfStream;/** * 倒出PDF合同 * @return */public String generateContract() throws Exception{Document document = new Document();BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);Font FontChinese = new Font(bfChinese); ByteArrayOutputStream buffer = new ByteArrayOutputStream();PdfWriter.getInstance(document, buffer);document.open();document.add(new Paragraph("中文Hello World",FontChinese));document.close();this.pdfStream = new ByteArrayInputStream(buffer.toByteArray());buffer.close();return SUCCESS;}public InputStream getPdfStream() {return pdfStream;}

热点排行