PDF中文报表

<%@ page
import="java.io.*,java.awt.Color,com.lowagie.text.*,com.lowagie.text.pdf.*"
contentType="text/html; charset=utf-8" autoFlush="true"%>

<%
response.setContentType("application/pdf");
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, buffer);
document.open();
BaseFont bfChinese = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
Paragraph test1 = new Paragraph("PDF我们是害虫", FontChinese);
document.add(test1);
Image img = Image.getInstance(pageContext.getServletContext()
.getRealPath("/")
+ "form\\b.jpg");
document.add(img);
document.close();
DataOutput output = new DataOutputStream(response.getOutputStream());
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
response.setCharacterEncoding("GBK");
for (int i = 0; i < bytes.length; i++) {
output.writeByte(bytes[i]);
}
out.clear();
//out = pageContext.pushBody();
%>

注意:
需要添加iTextAsian.jar包,提他编码:
Chinese Simplified:
STSong-Light and STSongStd-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V
Chinese Traditional:
MHei-Medium, MSung-Light and MSungStd-Light with the encodings UniCNS-UCS2-H and UniCNS-UCS2-V
Japanese:
HeiseiMin-W3, HeiseiKakuGo-W5 and KozMinPro-Regular with the encodings UniJIS-UCS2-H, UniJIS-UCS2-V, UniJIS-UCS2-HW-H and UniJIS-UCS2-HW-V
Korean:
HYGoThic-Medium, HYSMyeongJo-Medium and HYSMyeongJoStd with the encodings UniKS-UCS2-H and UniKS-UCS2-V
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值