在开发过程中,发现生成的PDF文件中,所有中文都不能显示,以”#“表示。
在ofbiz中,生成pdf的过程是:
1、访问xxx.pdf的url.
2、controller.xml中对*.pdf配置如下:
<handler name="screenfop" type="view"
class="org.ofbiz.widget.screen.ScreenFopViewHandler"/>
...
<view-map name="PicklistReport.pdf" type="screenfop"
page="component://warehouse/widget/warehouse/screens/shipping/ShippingScreens.xml#PicklistReportPDF"
content-type="application/pdf" encoding="none"/>
3、在ScreenFopViewHandler.java中,先把PicklistReport.fo.ftl渲染成xml
// render and obtain the XSL-FO
Writer writer = new StringWriter();
FopFactory fopFactory = ApacheFopFactory.instance();
ScreenRenderer screens = new ScreenRenderer(writer, null,
htmlScreenRenderer);
screens.populateContextForRequest(request, response,
servletContext);
// this is the object used to render forms from their
definitions
screens.getContext().put("formStringRenderer", new
FoFormRenderer(request, response));
screens.render(page);
然后由apache的FOP(Formatting Objects
Processor)对xml渲染,生成pdf文件,并放回到response中输出:
ByteArrayOutputStream out = new ByteArrayOutputStream();
TransformerFactory transFactory =
TransformerFactory.newInstance();
try {
Fop fop = fopFactory.newFop(contentType, out);
Transformer transformer = transFactory.newTransformer();
// set the input source (XSL-FO) and generate the output
stream of contentType
Reader reader = new StringReader(writer.toString());
Source src = new StreamSource(reader);
// Get handler that is used in the generation process
Result res = new SAXResult(fop.getDefaultHandler());
// Transform the FOP XML source
transformer.transform(src, res);
// We don't want to cache the images that get loaded by
the FOP engine
fopFactory.getImageFactory().clearCaches();
// set the content type and length
response.setContentType(contentType);
response.setContentLength(out.size());
// write to the browser
out.writeTo(response.getOutputStream());
response.getOutputStream().flush();
又一次看到中文被鄙视了,Apache FOP中不支持任务中文字体,所以要做下边三步,才能使pdf中的中文正常显示:
1、用FOP生成黑体字体配置文件simhei.xml,并把windows下的黑体文件simhei.ttf放在相同的目录下。在openb2c
中为:
%OPENB2C_HOME%\hot-deploy\opentaps-common\lib\DejaVu\
生成simhei.xml的命令为:
java -classpath
framework\webapp\lib\fop-0.93.jar;framework\base\lib\avalon-framework-4.2.0.jar;framework\webapp\lib\batik-all-1.6.jar;framework\base\lib\commons\commons-logging.jar;framework\base\lib\commons\commons-io-1.4.jar;framework\base\lib\serializer.jar;framework\base\lib\xalan.jar;framework\base\lib\xml-apis-2.8.1.jar;framework\webapp\lib\xmlgraphics-commons-1.1.jar
org.apache.fop.fonts.apps.TTFReader -ttcname "SimHei"
C:\WINDOWS\Fonts\simhei.ttf D:\simhei.xml
2、修改ofbiz中fop的配置文件fop.xconf
添加字体:simhei
<font metrics-url="simhei.xml" kerning="yes"
embed-url="simhei.ttf">
<font-triplet name="simhei" style="normal"
weight="normal"/>
</font>
3、修改*.fo.ftl模板文件,把font-family改为simhei
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
font-family="simhei">
重启看到pdf能正常显示中文了!
为我们公司做下广告易合信息技术yiihee.com
分享到:
相关推荐
NULL 博文链接:https://jeho0815.iteye.com/blog/1187197
OFBIZ_FOP中文支持.pdf
ofbiz_nutshell.pdf
NULL 博文链接:https://5ven.iteye.com/blog/2238197
ofbiz 英文 pdf,很好的ofbiz 初学者入门书籍,貌似网上其它资料很少
Ofbiz-EntityrefReport.pdf
ofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdfofbiz-birt.pdf
Ofbiz 和 Mysql中文乱码解决方法.docx
ofbiz 数据模型 中文手册 ofbiz 核心的数据模型 表结构和字段翻译
有兴趣的朋友可以自己生成,ant命令是:docs-all,该命令生成帮助文档时会获取操作系统语言设置,要生成英文文档请先将操作系统语言改为英语,要生成中文文档需要在docs-all命令中的添加属性encoding="GBK"(但生成的...
ofbiz后台应用 - 订单 - 订单查询/订单列表 - 订单明细 - "PDF" 报表, 中文报"#" 错误。 需导入中文解决
Ofbiz框架中的事务解析.pdf
OFBiz 主题修改文档
OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门
与hello资源结合使用,这是一个html5后台管理的模块,但实现了ofbiz主题针对具体应用的深度定制方法,里面只有一个页面,但基本思路已经包括在里面,希望大家能不断挖掘
OFBiz(Apache Open For Business)是一个开源框架,设计为帮助构建企业资源计划(ERP)软件。ERP是任何致力于整合所有业务处理及后台数据到一个系统的一个统称。实际上,OFBiz框架不仅帮助构建自定义软件,还打包有许多...
封装,你可以在一个简单的 XML 文件中定义数据库表结构,Ofbiz 会自动帮你在数据库建表,并动态生成映射对象, 你在程序中可以只考虑对 Object 的处理,Ofbiz 会自动通过事务逻辑更新到数据库中。Ofbiz 宣称的优点之...
你只需要下载这个文件包中的配置文件模板,虽后放到ofbiz1004\framework\appserver\templates\tomcat6下替换原来的文件,然后再到ofbiz目录下运行java -jar ofbiz.jar -setup tomcat6 ,完成后会得到一个setup的文件...
OFBiz API中文版.rar Apache OFBiz Cookbook Sep 2010.rar Opentaps widget使用说明.rar OFBiz.Development.2008.rar Groovy中文教程.rar freemarker中文手册.rar ofbiz10.04表结构.rar OFBiz开发指南.rar ...
OFBiz API中文版.chw