You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6.3 KiB
6.3 KiB
In [266]:
from reportlab.pdfgen.canvas import Canvas from reportlab.lib.pagesizes import A4 from reportlab.lib.units import mm from reportlab.lib.colors import pink, magenta, red, blue, yellow, lightyellow
In [277]:
c = Canvas("pdf/reportlab-canvas-A4-bag-of-words.pdf", pagesize=(210*mm, 297*mm), bottomup=0)
In [268]:
c.setPageSize(A4)
In [269]:
# Draw a background color c.setFillColor(lightyellow) c.rect(0, 0, A4[0], A4[1], stroke=0, fill=1)
In [270]:
# Draw a bag-of-words on the canvas, on random positions import random txt = open('txt/language.txt', 'r').read() words = txt.split()
In [271]:
# Set a font, change the font color from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics fontpath = "fonts/OSP-DIN.ttf" font = TTFont('OSP-DIN', fontpath) pdfmetrics.registerFont(font) c.setFont('OSP-DIN', 32) c.setFillColor(magenta)
In [275]:
# Draw on the canvas for n in range(100): x = random.randint(0, 190) y = random.randint(0, 280) word = random.choice(words).strip(',.') print(x, y, word) c.drawString(x*mm, y*mm, word)
37 107 a 24 100 formal 126 264 a 58 279 controls 41 250 an 36 142 program 111 153 programming 32 228 be 71 166 Originally 154 267 operations) 97 60 are 187 158 the 98 205 an 169 229 “code” 175 144 analog 166 9 yet 82 182 the 136 34 a 35 268 7 13 21 of 152 254 of 81 157 call 160 104 tomorrow 141 47 promises 140 220 of 155 201 The 62 59 terms.” 41 246 difficult 61 139 of 154 279 in 48 279 coded 59 88 artists 146 186 eventual 90 26 virus 102 261 act 55 265 computer 83 40 reflect 126 144 experiments 99 30 computation 5 221 concrete 96 129 occurs 19 89 computes 181 34 their 9 57 is 157 68 “performative” 19 95 computer 30 44 in 88 114 instructions 65 188 computer 81 149 German 70 207 whatever 113 31 representation 166 82 and 15 55 to 57 163 and 118 196 is 51 223 as 67 46 a 38 278 handle 136 134 Yet 35 170 poetry 146 111 “Interface”) 158 132 suitable 187 189 example 159 200 would 33 241 that 178 213 nothing 62 78 critically 166 205 of 169 42 more 122 154 itself 187 278 formal 85 59 ”Chapter 35 104 themselves 145 64 states 37 85 or 81 226 that 19 253 157 55 string 187 125 semantic 142 224 transformation 115 3 the 98 46 Wesley 61 202 a 178 32 in 110 211 command 169 240 be 166 82 symbols 34 192 languages 30 68 is 46 172 that 3 276 “natural 123 242 computer 100 123 common 162 248 that 140 31 it 9 146 are 165 10 in 132 271 control 173 276 But
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [273]:
# Add a small caption c.setFont('Courier', 10) c.setFillColor(blue) c.drawCentredString(105*mm, 285*mm, 'Random words from Language and Software Studies, by Florian Cramer (2005)')
In [274]:
# Save the PDF! #c.showPage() c.save()
In [ ]:
In [ ]: