292x Filetype PDF File size 0.56 MB Source: www.reportlab.com
ReportLab PDF Library
User Guide
ReportLab Version 3.6.12
Document generated on 2023/01/31 20:18:04
ReportLab
Wimbletech
35 Wimbledon Hill Road
London SW19 7NB, UK
User Guide Table of contents
Table of contents
Table of contents 2
Chapter 1 Introduction 6
1.1 About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 What is the ReportLab PDF Library? . . . . . . . . . . . . . . . . . . . 6
1.3 ReportLab's commercial software . . . . . . . . . . . . . . . . . . . . . 7
1.4 What is Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 Installation and Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Getting Involved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8 Site Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.9 Learning More About Python . . . . . . . . . . . . . . . . . . . . . . . 9
1.10 Goals of the 3.x release series . . . . . . . . . . . . . . . . . . . . . . 9
Chapter 2 Graphics and Text with pdfgen 11
2.1 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 More about the Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Drawing Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 The tools: the "draw" operations . . . . . . . . . . . . . . . . . . . . . 13
2.5 The toolbox: the "state change" operations . . . . . . . . . . . . . . . 15
2.6 Other canvas methods. . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.7 Coordinates (default user space) . . . . . . . . . . . . . . . . . . . . . 17
2.8 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.9 Color space checking . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.10 Color Overprinting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.11 Standard fonts and text objects . . . . . . . . . . . . . . . . . . . . . 27
2.12 Text object methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.13 Paths and Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.14 Rectangles, circles, ellipses . . . . . . . . . . . . . . . . . . . . . . . 39
2.15 Bezier curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.16 Path object methods . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.17 Further Reading: The ReportLab Graphics Library . . . . . . . . . . . 47
Chapter 3 Fonts and encodings 48
3.1 Unicode and UTF8 are the default input encodings . . . . . . . . . . . 48
3.2 Automatic output font substitution . . . . . . . . . . . . . . . . . . . . 48
Page 2
User Guide Table of contents
3.3 Using non-standard Type 1 fonts . . . . . . . . . . . . . . . . . . . . . 49
3.4 Standard Single-Byte Font Encodings . . . . . . . . . . . . . . . . . . 50
3.5 TrueType Font Support . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.6 Asian Font Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.7 RenderPM tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Chapter 4 Exposing PDF Special Capabilities 55
4.1 Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.2 Links and Destinations . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.3 Outline Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.4 Page Transition Effects . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.5 Internal File Annotations . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.6 Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.7 Interactive Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Chapter 5 PLATYPUS - Page Layout and Typography Using Scripts 65
5.1 Design Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.3 Flowables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.4 Guidelines for flowable positioning . . . . . . . . . . . . . . . . . . . . 67
5.5 Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.6 Documents and Templates . . . . . . . . . . . . . . . . . . . . . . . . 69
Chapter 6 Paragraphs 72
6.1 Using Paragraph Styles . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.2 Paragraph XML Markup Tags . . . . . . . . . . . . . . . . . . . . . . 78
6.3 Intra-paragraph markup . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.4 Bullets and Paragraph Numbering . . . . . . . . . . . . . . . . . . . . 82
Chapter 7 Tables and TableStyles 84
7.1 Table User Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.2 TableStyle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7.3 TableStyle User Methods . . . . . . . . . . . . . . . . . . . . . . . . . 85
7.4 TableStyle Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Chapter 8 Programming Flowables 91
8.1 DocAssign(self, var, expr, life='forever') . . . . . . . . . . . . . . . . . 91
8.2 DocExec(self, stmt, lifetime='forever') . . . . . . . . . . . . . . . . . . 91
Page 3
User Guide Table of contents
8.3 DocPara(self, expr, format=None, style=None, klass=None, escape=True)91
8.4 DocAssert(self, cond, format=None) . . . . . . . . . . . . . . . . . . . 91
8.5 DocIf(self, cond, thenBlock, elseBlock=[]) . . . . . . . . . . . . . . . . 91
8.6 DocWhile(self, cond, whileBlock) . . . . . . . . . . . . . . . . . . . . . 91
Chapter 9 Other Useful Flowables 92
9.1 Preformatted(text, style, bulletText=None, dedent=0,
maxLineLength=None, splitChars=None, newLineChars=None) . . . . 92
9.2 XPreformatted(text, style, bulletText=None, dedent=0, frags=None) . . 92
9.3 Image(filename, width=None, height=None) . . . . . . . . . . . . . . . 93
9.4 Spacer(width, height) . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.5 PageBreak() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.6 CondPageBreak(height) . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.7 KeepTogether(flowables) . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.8 TableOfContents() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.9 SimpleIndex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
9.10 ListFlowable(),ListItem() . . . . . . . . . . . . . . . . . . . . . . . . . 96
9.11 BalancedColumns() . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Chapter 10 Writing your own Flowable Objects 98
10.1 A very simple Flowable . . . . . . . . . . . . . . . . . . . . . . . . . 98
10.2 Modifying a Built in Flowable . . . . . . . . . . . . . . . . . . . . . . 99
Chapter 11 Graphics 101
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
11.2 General Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
11.3 Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
11.4 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
11.5 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
11.6 Bar Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.7 Line Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
11.8 Line Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
11.9 Pie Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
11.10 Legends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
11.11 Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
11.12 Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Appendix A ReportLab Demos 133
A.1 Odyssey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Page 4
no reviews yet
Please Login to review.