学习利用ReportLab生成PDF报表 -- RML基础(The Basics)

以下内容均参考RML User Guide文档(部分为译文,还有一份RML for idiots文档更适合入门),文档中的Demo都在 https://www.reportlab.com/documentation/rml-samples/

  1. RML简介
What is RML?

RML is the Report Markup Language - a member of the XML family of languages, and the XML dialect used
by rml2pdf to produce documents in Adobe's Portable Document Format (PDF).

在RML文件编写的同时可以嵌套很多语言Python、Perl等其他语言。利用RML中的标签来编写如同编写HTML一样,比调用API来生成PDF简单的多。

  1. 页面及页面结构
  • XML语法和RML:描述了一些XML和RML语法注意点。
  • prolog: 即每个RML文档的头部。
    • XML声明,非必要,但是推荐
 
* 文档类型定义 rml.dtd

* 紧随prolog,,filename参数是必须的,除filename外还有compression,invariant,debug参数。

...

  • Document forms
    用来定义一些所需的样式(内容可以为空)。
    • stylesheet/pageDrawing: 最基本,最简单。每个都代表一页。
    • template/stylesheet/story: 功能更强大。
  • a template:
    The template tells rml2pdf what should be on the page: headers, footers, any graphic elements you use as a
    background.
  • a stylesheet: The stylesheet is where the styles for a document are set. This tells the parser what fonts to use for paragraphs
    and paragraph headers, how to format tables and other things of that nature.
  • a story: The story is where the "meat" of the document is. Just like in a newspaper, the story is the bit you want people to
    read, as opposed to design elements or page markup. As such, this is where headers, paragraphs and the actual
    text is contained.
  1. 功能、格式等实在太多,暂只对于必要的常用功能、标签说明。