PDF 报表汉化步骤
-
报表的页眉和页脚在addons/custom/corporate_rml_header.rml
[[i] 本帖最后由 liuyuan_jq 于 2008-10-10 14:17 编辑 [/i]]
-
替换的工作直接交给linux完成。
-
获取中文字体文件 (本例中使用 simsun.ttc (全称: "SimSun"))
-
复制至 tiny/bin/reportlab/fonts/
这样你可以把字体文件拷贝到reportlab的目录下,
这个目录是在python的安装目录下的site-package>reportlab>font目录。
当然你将字体文件放在tiny/bin/reportlab/fonts/下也没有问题, -
编辑 tiny/report/render/rml2pdf/trml2pdf.py, 插入以下代码:
encoding = 'UTF-8'
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle, StyleSheet1def getZhSampleStyleSheet():
"""Returns a chinese stylesheet object"""
stylesheet = StyleSheet1()
stylesheet.add(ParagraphStyle(name='Normal',fontName='SimSun',fontSize=10,leading=12))
stylesheet.add(ParagraphStyle(name='BodyText',parent=stylesheet['Normal'],spaceBefore=6))
stylesheet.add(ParagraphStyle(name='Italic',parent=stylesheet['BodyText'],fontName='SimSun'))
stylesheet.add(ParagraphStyle(name='Heading1',parent=stylesheet['Normal'],fontName='SimSun',fontSize=18,leading=22,spaceAfter=6),alias='h1')stylesheet.add(ParagraphStyle(name='Title',parent=stylesheet['Normal'],fontName='SimSun',fontSize=18,leading=22,alignment=TA_CENTER,spaceAfter=6),alias='title') stylesheet.add(ParagraphStyle(name='Heading2',parent=stylesheet['Normal'],fontName='SimSun',fontSize=14,leading=18,spaceBefore=12,spaceAfter=6),alias='h2') stylesheet.add(ParagraphStyle(name='Heading3',parent=stylesheet['Normal'],fontName='SimSun',fontSize=12,leading=14,spaceBefore=12,spaceAfter=6),alias='h3') stylesheet.add(ParagraphStyle(name='Bullet',parent=stylesheet['Normal'],firstLineIndent=0,spaceBefore=3),alias='bu') stylesheet.add(ParagraphStyle(name='Definition',parent=stylesheet['Normal'],firstLineIndent=0,leftIndent=36,bulletIndent=0,spaceBefore=6,bulletFontName='SimSun'),alias='df') stylesheet.add(ParagraphStyle(name='Code',parent=stylesheet['Normal'],fontName='SimSun',fontSize=8,leading=8.8,firstLineIndent=0,leftIndent=36)) return stylesheet
-
在同样的文件中搜索 reportlab.lib.styles.getSampleStyleSheet() 用 getZhSampleStyleSheet() 替换(共六处)
-
编辑 tiny/report/render/rml2pdf/init.py, 插入以下代码:
#add by chenzp
from reportlab.lib.fonts import addMapping
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile
from reportlab.lib.fonts import addMappingpdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
pdfmetrics.registerFont(TTFont('SimSun','simsun.ttc'))
pdfmetrics.registerFont(TTFont('SimHei','simhei.ttf'))
pdfmetrics.registerFont(TTFont('SimKai','SIMKAI.TTF'))
pdfmetrics.registerFont(TTFont('SimFang','SIMFANG.TTF'))
pdfmetrics.registerFont(TTFont('SimLi','SIMLI.TTF'))
pdfmetrics.registerFont(TTFont('SimYou','SIMYOU.TTF'))for facename in ['SimSun','SimHei','SimKai','SimFang','SimLi','SimYou']:
addMapping(facename, 0, 0, facename) #normal
addMapping(facename, 0, 1, facename) #italic
addMapping(facename, 1, 0, facename) #bold
addMapping(facename, 1, 1, facename) #italic and bold6.回到tinyerp的安装目录 。使用以下命令使所有的报表使用SimSun 字体:
sed -i 's/Times-Roman/SimSun/g'
find ./addons -name "*.rml"
sed -i 's/Times-BoldItalic/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Times-Bold/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Times-Italic/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Helvetica-BoldOblique/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Helvetica-BoldOblique/SimSun/g'
find ./addons -name "*.xsl"
sed -i 's/Helvetica-Bold/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Helvetica-Bold/SimSun/g'find ./addons -name "*.xsl"
sed -i 's/Helvetica-Oblique/SimSun/g'find ./addons -name "*.xsl"
sed -i 's/Helvetica/SimSun/g'
find ./addons -name "*.rml"
sed -i 's/Helvetica/SimSun/g'find ./addons -name "*.xsl"
sed -i 's/Courier-Bold/SimSun/g'find ./addons -name "*.rml"
sed -i 's/Courier/SimSun/g'find ./addons -name "*.xsl"
sed -i 's/Courier/SimSun/g'find ./addons -name "*.rml"
搞定!
[[i] 本帖最后由 openSourceERP 于 2008-10-13 13:58 编辑 [/i]]
-
-
用论坛0.33不能用这个办法,因为版本不同功能上有区别。
用0.33的需要手动用命令行转换sxw文件为rml
在tiny_sxw2rml-0.9.3包里在目录执行如果不下载0.33的addonsbase_report_designerwizardtiny_sxw2rmltiny_sxw2rml-0.9.3下也有
命令为:tiny_sxw2rml.py xyz.sxw>xyz,rml (xyz为文件名)不过要修改下normalized_oo2rml.xsl这个文件不然中文都成方块
在文件的末尾处把所有Times-XXX都改成simsun[[i] 本帖最后由 simon 于 2008-10-10 14:49 编辑 [/i]]
-
[quote]原帖由 [i]oldrev[/i] 于 2008-10-10 14:30 发表 www.shine-it.net/redirect.php?goto=findpost&pid=1411&ptid=333
楼上的大哥,sed 命令是错的,把 Arial Unicode MS 改成 SimSun [/quote]
lz 果然很强。有没有openoffice的报表插件?