RML制作PDF文档

1.环境搭建

**Python2.7.11**

下载地址:https://www.python.org/downloads/  

注意:最好不要使用Python 3以上的版本,目前很多库对3以上的版本支持不是很好  

**preppy**  

安装方式:Python -m pip install preppy 默认是下载最新版本 (指定版本:Python -m pip install preppy2.3.2)  

源码下载地址:https://pypi.python.org/pypi/preppy/  

**pyrxp**  

安装方式:Python -m pip install pyrxp 默认是下载最新版本 (指定版本:Python -m pip install pyRXP-2.1.0)  

源码下载地址:https://pypi.python.org/pypi/pyRXP 注意选择对应python版本下载

**reportlab**  

安装方式:Python -m pip install reportlab 默认是下载最新版本 (指定版本:Python -m pip install reportlab-3.2.0)  

源码下载地址:https://pypi.python.org/pypi/reportlab/

**trml2pdf**

安装方式:Python -m pip install trml2pdf 默认是下载最新版本 (指定版本:Python -m pip install trml2pdf-3.2.0)  

源码下载地址:https://pypi.python.org/pypi/trml2pdf

2 、测试RML文档转换为

繁琐的环境搭建完成后就要写RML转换为pdf的工具类了。。。。。下班了回家在写。 2016.2.3

编写pdf工具类:

<span style="background-color: rgb(255, 255, 153);"><span style="color:#ff0000;font-size:24px;"># coding=gbk</span><span style="color:#343434;font-size:24px;">   </span><span style="color: rgb(52, 52, 52); font-family: 'Source Code Pro', monospace;"><span style="font-size:14px;">#如果代码中有中文字符需加入这段代码</span></span></span><span style="color:#343434;"><span style="font-size:24px;">
</span><span style="font-size:18px;">import sys
import os
import unittest
import trml2pdf  # dev mode: python setup.py develop

from six import text_type</span></span><span style="color:#343434;font-size:24px;">

</span>
<span style="color:#343434;"></span><pre name="code" class="python" style="font-size:24px;"><span style="color: rgb(52, 52, 52);font-size:24px; background-color: rgb(255, 255, 153);">#加入这段代码主要是用py2exe制作exe时py2exe无法找到rl_settings</span>
from reportlab import rl_settings

 
<span style="font-size:18px;color:#343434;">import reportlab.lib.styles</span>
<span style="font-size:18px;color:#343434;">
</span>
<span style="font-size:18px;color:#343434;"><span style="background-color: rgb(255, 255, 153);">#以下两个包用来注册字体,应为我们文档需要显示中文,所以需要注册中文字体
from reportlab.pdfbase import pdfmetrics,ttfonts
from reportlab.lib.fonts import addMapping</span>   </span><span style="color:#343434;font-size:24px;">

</span><span style="font-size:18px;color:#343434;">EXAMPLES_DIR = "..\examples"</span>
<span style="color:#343434;font-size:24px;">#</span><span style="font-size:14px;"><span style="color:#343434;">用</span><span style="color: rgb(52, 52, 52); font-family: 'Source Code Pro', monospace;">os.path.realpath(os.path.dirname(os.path.abspath(sys.argv[0])))替代__file__  py2exe不认识__file__</span></span><span style="color:#343434;"><span style="font-size:24px;">
</span><span style="font-size:18px;">TESTS_DIR = os.path.dirname(os.path.realpath(os.path.dirname(os.path.abspath(sys.argv[0]))))
FONT_DIR = "\templates\font"
# sys.path.append(EXAMPLES_DIR)

class TestExamples(unittest.TestCase):
    """run pdf genration using all files in examples."""

    def test_run_all(self):
        try:            
            # change current dir, there are relative references to images in rmls            
            work_dir = os.getcwd()
            os.chdir(EXAMPLES_DIR)
            <span style="background-color: rgb(255, 255, 153);">pdfmetrics.registerFont(ttfonts.TTFont('song', "C:\Windows\Fonts\simsun.ttc")) #注册字体的方法</span>
            self._run_all_examples()
        finally:
            os.chdir(work_dir)

    def _run_all_examples(self):        
        for name in os.listdir('.'):
            if name.endswith(".rml"):
                path = name  # '{}/{}'.format(EXAMPLES_DIR, name)
                print('running: {}'.format(path))
                with open(path, "r") as f:
                    output = trml2pdf.parseString(f.read())
                self.assertIsNotNone(output)                
                with open(TESTS_DIR + '/templates/bug8.pdf', 'wb') as w:
                    w.write(output)


# does not work, todo find a solution
# class TestOutput(unittest.TestCase):
#     def test_bug8(self):
#         with open(TESTS_DIR + '/templates/bug_8.rml', "r") as f:
#             output = trml2pdf.parseString(f.read())
#             print(output)
#         self.assertNotIn('\\n', text_type(output))  # not so easy to test PDF content, it is encoded
#         with open(TESTS_DIR + '/templates/bug8.pdf', 'wb') as w:
#             w.write(output)


if __name__ == "__main__":
    unittest.main()</span></span>
代码 中的路径,自己改成合适的就OK了。。。

工具类写完后,用现有的RML做测试,运行测试OK。。。

把脚本打包成exe可执行程序的方法有两种,一种是利用Py2exe,一种是利用PyInstaller

使用方法找度娘就是了。。。


Python各种依赖包地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/

Systems Modeling Language (OMG SysML™) 1.6.pdf The purpose of this International Standard is to specify the Systems Modeling Language (SysML), a general-purpose modeling language for systems engineering. Its intent is to specify the language so that systems engineering modelers may learn to apply and use SysML; modeling tool vendors may implement and support SysML; and both can provide feedback to improve future versions. Note that a definition of “system” and “systems engineering” can be found inISO/ IEC 15288. SysML reuses a subset of UML 2.5 and provides additional extensions to address the requirements in UML for SE. SysML uses the UML 2.5 extension mechanisms as further elaborated in Clause 17 as the primary mechanism to specify the extensions to UML 2.5. This revision of SysML relies on several new features incorporated into UML 2.5. Any use of the term “UML 2” or “UML” in this specification, unless otherwise noted, will refer to UML 2.5 in general and the UML 2.5 specification in particular. Since SysML uses UML 2.5 as its foundation, systems engineers modeling with SysML and software engineers modeling with UML 2.5 will be able to collaborate on models of software-intensive systems. This will improve communication among the various stakeholders who participate in the systems development process and promote interoperability among modeling tools. It is anticipated that SysML will be customized to model domain-specific applications, such as automotive, aerospace, communication, and information systems. SysML is designed to provide simple but powerful constructs for modeling a wide range of systems engineering problems. It is particularly effective in specifying requirements, structure, behavior, allocations, and constraints on system properties to support engineering analysis. The language is intended to support multiple processes and methods such as structured, object-oriented, and others, but each methodology may impose additional constraints
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值