在Playframework中,通过浏览器弹出窗口的方式下载PDF文件。
PDF文件是用iText生成的,支持中文。
获取中文自己的一段配置文件的代码:
private static final String pdfFont = Play.configuration.getProperty("pdf.font");
配置文件
pdf.font=c:/windows/fonts/simsun.ttc,1
创建文件并下载
List logs = Dailylog.find("userid = ? order by pubtime desc", Long.parseLong(session.get("USERID"))).fetch();
response.contentType = "application/pdf";
//A4纸大小,到各个边框的距离为36
document = new Document(PageSize.A4, 36, 36, 36, 36);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
//增加对中文的支持
BaseFont baseFont = BaseFont.createFont(pdfFont, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(baseFont, 12, Font.NORMAL);
PdfWriter.getInstance(document, buffer);
//设