displaytag 中的 导出pdf 功能的改造

一、中文问题:
目前网上谈到较多的是一种方法,且多为转载;对其源代码进行分析后进行了另一种改造;具体如下:

displaytag-1.1\displaytag\src\main\java\org\displaytag\render\ItextTableWriter.java
ItextTableWriter:
--
private Font getFont(float size, int style, Color color) {
Font font = null;
try {
font = new Font(BaseFont.createFont("STSong-Light"/* "Helvetica" */,
"UniGB-UCS2-H"/* BaseFont.WINANSI */, false), size, style,
color);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (font == null) {
font = FontFactory.getFont(FontFactory.HELVETICA, size, style,
color);
}
}

return font;
}

更改所有的getFont方法使用上边的getFont方法,以下仅为其中一例
protected Font getTableFont() {
return getFont(10, Font.NORMAL, new Color(0x00, 0x00, 0x00));
}
这样更改后,导出的报表标题和footer都是中文了。


二、添加二级标题或者是报表头功能
(1)在displaytag-12.tld中添加以下代码
<tag>
<name>header</name>
<tag-class>org.displaytag.tags.TableHeaderTag</tag-class>
<body-content>JSP</body-content>
<display-name>header</display-name>
<description>
Tag which should be nested into a table tag to provide extra header row(s). The body of the tag will be inserted
before the automatically-generated header row, within the thead tag.
</description>
<attribute>
<name>media</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<description>
Use this attribute to keep a header from being output during an export. The caption will only render for the
named media type(s) - it won't be added to the table if the current request media is not supported. Can be any
space separated combination of 'html', 'csv', 'xml', 'all', or 'excel'. Defaults to 'all'. See the export page
in the example webapp for more details.
</description>
</attribute>
<example>
<![CDATA[
<display:table name="someList" varTotals="totals">
<display:column property="itemName"/>
<display:column property="price" total="true"/>
<display:header>
<tr>
<td>Total Bill:</td>
<td><c:out value="${totals.column2}" /></td>
<tr>
</display:header>
</display:table>
]]>
</example>
</tag>
(2)在display中添加相应代码
<1>添加src/main/java/org/displaytag/tags/TableHeaderTag.java类。
<2>src/main/java/org/displaytag/model/TableModel.java修改 :
添加private String header属性,并生成set、get方法;
在toString()增加.append("header", this.header) //$NON-NLS-1;
<3>src/main/java/org/displaytag/render/HtmlTableWriter.java
if (model.getHeader() != null) {
write(model.getHeader());
}

<4>src/main/java/org/displaytag/tags/TableTag.java
添加private String header属性,并生成set、get方法;
置空方法中添加this.header = null;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值