1from reportlab.lib import styles 2from reportlab.lib import colors 3from reportlab.lib.units import cm 4from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY 5from reportlab.platypus import Preformatted, Paragraph, Frame, \ 6 Image, Table, TableStyle, Spacer 7from reportlab.pdfbase import pdfmetrics 8from reportlab.pdfbase.ttfonts import TTFont 9 10 11def getParagraphStyles(): 12 """Returns a dictionary of styles to get you started. 13 14 We will provide a way to specify a module of these. Note that 15 this just includes TableStyles as well as ParagraphStyles for any 16 tables you wish to use. 17 """ 18 19 pdfmetrics.registerFont(TTFont('Verdana','verdana.ttf')) 20 pdfmetrics.registerFont(TTFont('Verdana-Bold','verdanab.ttf')) 21 pdfmetrics.registerFont(TTFont('Verdana-Italic','verdanai.ttf')) 22 pdfmetrics.registerFont(TTFont('Verdana-BoldItalic','verdanaz.ttf')) 23 pdfmetrics.registerFont(TTFont('Arial Narrow','arialn.ttf')) 24 pdfmetrics.registerFont(TTFont('Arial Narrow-Bold','arialnb.ttf')) 25 pdfmetrics.registerFont(TTFont('Arial Narrow-Italic','arialni.ttf')) 26 pdfmetrics.registerFont(TTFont('Arial Narrow-BoldItalic','arialnbi.ttf')) 27 28 stylesheet = {} 29 ParagraphStyle = styles.ParagraphStyle 30 31 para = ParagraphStyle('Normal', None) #the ancestor of all 32 para.fontName = 'Verdana' 33 para.fontSize = 28 34 para.leading = 32 35 para.spaceAfter = 6 36 stylesheet['Normal'] = para 37 38 #This one is spaced out a bit... 39 para = ParagraphStyle('BodyText', stylesheet['Normal']) 40 para.spaceBefore = 12 41 stylesheet['BodyText'] = para 42 43 #Indented, for lists 44 para = ParagraphStyle('Indent', stylesheet['Normal']) 45 para.leftIndent = 60 46 para.firstLineIndent = 0 47 stylesheet['Indent'] = para 48 49 para = ParagraphStyle('Centered', stylesheet['Normal']) 50 para.alignment = TA_CENTER 51 stylesheet['Centered'] = para 52 53 para = ParagraphStyle('BigCentered', stylesheet['Normal']) 54 para.fontSize = 32 55 para.alignment = TA_CENTER 56 para.spaceBefore = 12 57 para.spaceAfter = 12 58 stylesheet['BigCentered'] = para 59 60 para = ParagraphStyle('Italic', stylesheet['BodyText']) 61 para.fontName = 'Verdana-Italic' 62 stylesheet['Italic'] = para 63 64 para = ParagraphStyle('Title', stylesheet['Normal']) 65 para.fontName = 'Arial Narrow-Bold' 66 para.fontSize = 48 67 para.leading = 58 68 para.alignment = TA_CENTER 69 stylesheet['Title'] = para 70 71 para = ParagraphStyle('Heading1', stylesheet['Normal']) 72 para.fontName = 'Arial Narrow-Bold' 73 para.fontSize = 40 74 para.leading = 44 75 para.alignment = TA_CENTER 76 stylesheet['Heading1'] = para 77 78 para = ParagraphStyle('Heading2', stylesheet['Normal']) 79 para.fontName = 'Verdana' 80 para.fontSize = 32 81 para.leading = 36 82 para.spaceBefore = 32 83 para.spaceAfter = 12 84 stylesheet['Heading2'] = para 85 86 para = ParagraphStyle('Heading3', stylesheet['Normal']) 87 para.fontName = 'Verdana' 88 para.spaceBefore = 20 89 para.spaceAfter = 6 90 stylesheet['Heading3'] = para 91 92 para = ParagraphStyle('Heading4', stylesheet['Normal']) 93 para.fontName = 'Verdana-BoldItalic' 94 para.spaceBefore = 6 95 stylesheet['Heading4'] = para 96 97 para = ParagraphStyle('Bullet', stylesheet['Normal']) 98 para.firstLineIndent = 0 99 para.leftIndent = 56 100 para.spaceBefore = 6 101 para.bulletFontName = 'Symbol' 102 para.bulletFontSize = 24 103 para.bulletIndent = 20 104 stylesheet['Bullet'] = para 105 106 para = ParagraphStyle('Bullet2', stylesheet['Normal']) 107 para.firstLineIndent = 0 108 para.leftIndent = 80 109 para.spaceBefore = 6 110 para.fontSize = 24 111 para.bulletFontName = 'Symbol' 112 para.bulletFontSize = 20 113 para.bulletIndent = 60 114 stylesheet['Bullet2'] = para 115 116 para = ParagraphStyle('Definition', stylesheet['Normal']) 117 #use this for definition lists 118 para.firstLineIndent = 0 119 para.leftIndent = 60 120 para.bulletIndent = 0 121 para.bulletFontName = 'Verdana-BoldItalic' 122 para.bulletFontSize = 24 123 stylesheet['Definition'] = para 124 125 para = ParagraphStyle('Code', stylesheet['Normal']) 126 para.fontName = 'Courier' 127 para.fontSize = 16 128 para.leading = 18 129 para.leftIndent = 36 130 stylesheet['Code'] = para 131 132 para = ParagraphStyle('PythonCode', stylesheet['Normal']) 133 para.fontName = 'Courier' 134 para.fontSize = 16 135 para.leading = 18 136 para.leftIndent = 36 137 stylesheet['Code'] = para 138 139 para = ParagraphStyle('Small', stylesheet['Normal']) 140 para.fontSize = 12 141 para.leading = 14 142 stylesheet['Small'] = para 143 144 #now for a table 145 ts = TableStyle([ 146 ('FONT', (0,0), (-1,-1), 'Arial Narrow', 22), 147 ('LINEABOVE', (0,1), (-1,1), 2, colors.green), 148 ('LINEABOVE', (0,2), (-1,-1), 0.25, colors.black), 149 ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), 150 ('LINEBEFORE', (0,1), (-1,-1), 2, colors.black), 151 ('LINEAFTER', (0,1), (-1,-1), 2, colors.black), 152 ('ALIGN', (4,1), (-1,-1), 'RIGHT'), #all numeric cells right aligned 153 ('TEXTCOLOR', (0,2), (0,-1), colors.black), 154 ('BACKGROUND', (0,1), (-1,1), colors.Color(0,0.7,0.7)) 155 ]) 156 stylesheet['table1'] = ts 157 158 return stylesheet 159