使用Itext生成PDF绝对定位流入web网页
2015-01-27 19:49
351 查看
public void PDF(){
<span style="white-space:pre"> </span>ByteArrayOutputStream stream = new ByteArrayOutputStream();
<span style="white-space:pre"> </span>//自定义界面大小,上下左右边距
<span style="white-space:pre"> </span>Document document = new Document(new Rectangle(50,50), 0, 0, 0, 0);
<span style="white-space:pre"> </span>PdfWriter writer = PdfWriter.getInstance(document, stream);
<span style="white-space:pre"> </span>document.open(); // 打开 Document 文档
<span style="white-space:pre"> </span>PdfContentByte cb = writer.getDirectContent(); <span style="white-space:pre"> </span>BaseFont bf = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",false);//设置字体
<span style="white-space:pre"> </span>cb.beginText();
<span style="white-space:pre"> </span>cb.setFontAndSize(bf, 12);//字体和子号
<span style="white-space:pre"> </span>cb.setTextMatrix(50,50);//字体显示位置
<span style="white-space:pre"> </span>cb.showText();//内容
<span style="white-space:pre"> </span>cb.endText();
<span style="white-space:pre"> </span>document.close();//关闭文档
<span style="white-space:pre"> </span>//设置响应文档类型为pdf <span style="white-space:pre"> </span>getResponse().setContentType("application/pdf"); <span style="white-space:pre"> </span>//设置响应数据大小 <span style="white-space:pre"> </span>getResponse().setContentLength(stream.size()); <span style="white-space:pre"> </span>//将pdf数据流写入响应数据流中 <span style="white-space:pre"> </span>ServletOutputStream out = getResponse().getOutputStream();
<span style="white-space:pre"> </span>stream.writeTo(out); <span style="white-space:pre"> </span>out.flush(); <span style="white-space:pre"> </span>out.close();下载ITEXT包
下载ITEXT依赖中文包
相关文章推荐
- java使用itext导出PDF文本绝对定位
- java使用itext导出PDF文本绝对定位(实现方法)
- Itext 生成 pdf文件使用方法:
- 使用Java组件itext 生成pdf介绍
- 滴水穿石--Java 生成PDF文件--iText使用之入门
- 使用iText生成带底图的PDF
- 使用itext将html生成pdf中文换行问题解决方案2
- 使用ITEXT与JAVA生成PDF报表
- 生成pdf,使用itext
- 滴水穿石--Java 生成PDF文件--iText使用之插入图片和中文乱码
- Java 使用 iText动态生成PDF文档
- 如何在使用itext生成pdf文档时给文档添加背景图片
- itext使用模板生成pdf文件
- 使用itext组件生成PDF文件
- java使用iText生成pdf:解决中文
- 使用itext生成pdf
- 如何在使用itext生成pdf文档时给文档添加背景图片
- 用Java生成PDF,iText使用.
- 生成PDF文件-使用iText制作复杂表格
- 使用itext将html生成pdf中文换行问题解决方案