author | rgbecker |
Wed, 17 May 2000 22:18:09 +0000 | |
changeset 227 | fa5b4d81f471 |
parent 226 | a9acb67cdef7 |
child 249 | 1d9ea4f00348 |
permissions | -rw-r--r-- |
197 | 1 |
############################################################################### |
2 |
# |
|
3 |
# ReportLab Public License Version 1.0 |
|
4 |
# |
|
5 |
# Except for the change of names the spirit and intention of this |
|
6 |
# license is the same as that of Python |
|
7 |
# |
|
8 |
# (C) Copyright ReportLab Inc. 1998-2000. |
|
9 |
# |
|
10 |
# |
|
11 |
# All Rights Reserved |
|
12 |
# |
|
13 |
# Permission to use, copy, modify, and distribute this software and its |
|
14 |
# documentation for any purpose and without fee is hereby granted, provided |
|
15 |
# that the above copyright notice appear in all copies and that both that |
|
16 |
# copyright notice and this permission notice appear in supporting |
|
17 |
# documentation, and that the name of ReportLab not be used |
|
18 |
# in advertising or publicity pertaining to distribution of the software |
|
19 |
# without specific, written prior permission. |
|
20 |
# |
|
21 |
# |
|
22 |
# Disclaimer |
|
23 |
# |
|
24 |
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
|
25 |
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
|
26 |
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT |
|
27 |
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
|
28 |
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
|
29 |
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
30 |
# PERFORMANCE OF THIS SOFTWARE. |
|
31 |
# |
|
32 |
############################################################################### |
|
33 |
# $Log: doctemplate.py,v $ |
|
227 | 34 |
# Revision 1.11 2000/05/17 22:17:38 rgbecker |
35 |
# Renamed BasicFrame to Frame |
|
36 |
# |
|
226 | 37 |
# Revision 1.10 2000/05/17 16:29:40 rgbecker |
38 |
# Removal of SimpleFrame |
|
227 | 39 |
# |
225 | 40 |
# Revision 1.9 2000/05/17 15:37:33 rgbecker |
41 |
# Changes related to removal of SimpleFlowDocument |
|
226 | 42 |
# |
221 | 43 |
# Revision 1.8 2000/05/16 16:15:16 rgbecker |
44 |
# Changes related to removal of SimpleFlowDocument |
|
225 | 45 |
# |
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
46 |
# Revision 1.7 2000/05/16 14:28:55 rgbecker |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
47 |
# Fixes/Changes to get testplatypus to work with new framework |
221 | 48 |
# |
214 | 49 |
# Revision 1.6 2000/05/15 15:07:32 rgbecker |
50 |
# Added drawPage |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
51 |
# |
206 | 52 |
# Revision 1.5 2000/05/13 08:33:53 rgbecker |
53 |
# fix typo in import |
|
214 | 54 |
# |
204 | 55 |
# Revision 1.4 2000/05/12 16:21:02 rgbecker |
56 |
# _donothing explicit import |
|
206 | 57 |
# |
200 | 58 |
# Revision 1.3 2000/05/12 14:53:38 rgbecker |
59 |
# Handle splitting error in build |
|
204 | 60 |
# |
199 | 61 |
# Revision 1.2 2000/05/12 14:45:31 rgbecker |
62 |
# Single actions only in ActionFlowables |
|
200 | 63 |
# |
197 | 64 |
# Revision 1.1 2000/05/12 12:53:33 rgbecker |
65 |
# Initial try at a document template class |
|
199 | 66 |
# |
227 | 67 |
__version__=''' $Id: doctemplate.py,v 1.11 2000/05/17 22:17:38 rgbecker Exp $ ''' |
197 | 68 |
__doc__=""" |
69 |
More complicated Document model |
|
70 |
""" |
|
71 |
from layout import * |
|
206 | 72 |
from layout import _doNothing |
197 | 73 |
from types import * |
74 |
import sys |
|
75 |
||
76 |
class ActionFlowable(Flowable): |
|
77 |
'''This Flowable is never drawn, it can be used for data driven controls''' |
|
199 | 78 |
def __init__(self,action=[]): |
79 |
if type(action) not in (ListType, TupleType): |
|
80 |
action = (action,) |
|
81 |
self.action = action |
|
197 | 82 |
|
83 |
def wrap(self, availWidth, availHeight): |
|
84 |
raise NotImplementedError |
|
85 |
||
86 |
def draw(self): |
|
87 |
raise NotImplementedError |
|
88 |
||
89 |
def apply(self,doc): |
|
199 | 90 |
action = self.action[0] |
91 |
args = tuple(self.action[1:]) |
|
92 |
try: |
|
93 |
apply(getattr(doc,'handle_'+action), args) |
|
94 |
except AttributeError: |
|
95 |
raise NotImplementedError, "Can't handle ActionFlowable(%s)" % action |
|
96 |
except: |
|
97 |
t, v, None = sys.exc_info() |
|
98 |
raise t, "%s\n handle_%s args=%s"%(v,action,args) |
|
197 | 99 |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
100 |
def __call__(self): |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
101 |
return self |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
102 |
|
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
103 |
FrameBreak = ActionFlowable('frameEnd') |
197 | 104 |
PageBegin = ActionFlowable('pageBegin') |
105 |
||
106 |
class NextPageTemplate(ActionFlowable): |
|
107 |
def __init__(self,pt): |
|
199 | 108 |
ActionFlowable.__init__(self,('nextPageTemplate',pt)) |
197 | 109 |
|
110 |
class PageTemplate: |
|
111 |
""" |
|
227 | 112 |
essentially a list of Frames and an onPage routine to call at the start |
197 | 113 |
of a page when this is selected. |
214 | 114 |
derived classes can also implement drawPage if they want |
197 | 115 |
""" |
116 |
def __init__(self,id=None,frames=[],onPage=None): |
|
117 |
if type(frames) not in (ListType,TupleType): frames = [frames] |
|
227 | 118 |
assert filter(lambda x: not isinstance(x,Frame), frames)==[], "frames argument error" |
197 | 119 |
self.id = id |
120 |
self.frames = frames |
|
121 |
self.onPage = onPage or _doNothing |
|
122 |
||
214 | 123 |
def drawPage(self,canv,doc): |
124 |
''' Override this if you want additional functionality or prefer a class |
|
125 |
based page routine |
|
126 |
''' |
|
127 |
pass |
|
128 |
||
197 | 129 |
class BaseDocTemplate: |
130 |
""" |
|
131 |
First attempt at defining a document template class. |
|
132 |
||
133 |
The basic idea is simple. |
|
134 |
0) The document has a list of data associated with it |
|
135 |
this data should derive from flowables. We'll have |
|
136 |
special classes like PageBreak, FrameBreak to do things |
|
137 |
like forcing a page end etc. |
|
138 |
||
139 |
1) The document has one or more page templates. |
|
140 |
||
141 |
2) Each page template has one or more frames. |
|
142 |
||
143 |
3) The document class provides base methods for handling the |
|
144 |
story events and some reasonable methods for getting the |
|
145 |
story flowables into the frames. |
|
146 |
||
147 |
4) The document instances can override the base handler routines. |
|
148 |
""" |
|
149 |
def __init__(self, filename, pagesize=DEFAULT_PAGE_SIZE, pageTemplates=[], showBoundary=0, |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
150 |
leftMargin=inch, rightMargin=inch, topMargin=inch, bottomMargin=inch, |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
151 |
allowSplitting=1): |
197 | 152 |
|
153 |
self.pageTemplates = [] |
|
154 |
self.addPageTemplates(pageTemplates) |
|
155 |
self.filename = filename |
|
156 |
self.showBoundary = showBoundary |
|
157 |
self.leftMargin = leftMargin |
|
158 |
self.bottomMargin = bottomMargin |
|
159 |
self.rightMargin = pagesize[0] - rightMargin |
|
160 |
self.topMargin = pagesize[1] - topMargin |
|
161 |
self.width = self.rightMargin - self.leftMargin |
|
162 |
self.height = self.topMargin - self.bottomMargin |
|
163 |
self.pagesize = pagesize |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
164 |
self.allowSplitting = allowSplitting |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
165 |
self._pageBreakQuick = 1 |
197 | 166 |
|
167 |
def clean_hanging(self): |
|
168 |
while len(self._hanging): |
|
169 |
self.handle_flowable(self._hanging) |
|
170 |
||
171 |
def addPageTemplates(self,pageTemplates): |
|
172 |
if type(pageTemplates) not in (ListType,TupleType): |
|
173 |
pageTemplates = [pageTemplates] |
|
174 |
assert filter(lambda x: not isinstance(x,PageTemplate), pageTemplates)==[], "pageTemplates argument error" |
|
175 |
for t in pageTemplates: |
|
176 |
self.pageTemplates.append(t) |
|
177 |
||
178 |
def handle_documentBegin(self): |
|
179 |
self._hanging = [PageBegin] |
|
180 |
self.pageTemplate = self.pageTemplates[0] |
|
181 |
self.page = 0 |
|
182 |
||
183 |
def handle_pageBegin(self): |
|
184 |
'''shouldn't normally be called directly''' |
|
185 |
self.page = self.page + 1 |
|
214 | 186 |
self.pageTemplate.drawPage(self.canv,self) |
197 | 187 |
self.pageTemplate.onPage(self.canv,self) |
188 |
if hasattr(self,'_nextFrameIndex'): |
|
189 |
del self._nextFrameIndex |
|
190 |
self.frame = self.pageTemplate.frames[0] |
|
191 |
self.handle_frameBegin() |
|
192 |
||
193 |
def handle_pageEnd(self): |
|
194 |
''' show the current page |
|
195 |
check the next page template |
|
196 |
hang a page begin |
|
197 |
''' |
|
198 |
self.canv.showPage() |
|
199 |
if hasattr(self,'_nextPageTemplateIndex'): |
|
200 |
self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex] |
|
201 |
del self._nextPageTemplateIndex |
|
202 |
self._hanging.append(PageBegin) |
|
203 |
||
204 |
def handle_pageBreak(self): |
|
205 |
'''some might choose not to end all the frames''' |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
206 |
if self._pageBreakQuick: |
197 | 207 |
self.handle_pageEnd() |
208 |
else: |
|
209 |
n = len(self._hanging) |
|
210 |
while len(self._hanging)==n: |
|
211 |
self.handle_frameEnd() |
|
212 |
||
213 |
def handle_frameBegin(self,*args): |
|
214 |
self.frame._reset() |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
215 |
if self.showBoundary or self.frame.showBoundary: |
226 | 216 |
self.frame.drawBoundary(self.canv) |
197 | 217 |
|
218 |
def handle_frameEnd(self): |
|
219 |
''' Handles the semantics of the end of a frame. This includes the selection of |
|
220 |
the next frame or if this is the last frame then invoke pageEnd. |
|
221 |
''' |
|
222 |
if hasattr(self,'_nextFrameIndex'): |
|
223 |
frame = self.pageTemplate.frames[self._nextFrameIndex] |
|
224 |
del self._nextFrameIndex |
|
204 | 225 |
self.handle_frameBegin() |
197 | 226 |
elif hasattr(self.frame,'lastFrame') or self.frame is self.pageTemplate.frames[-1]: |
227 |
self.handle_pageEnd() |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
228 |
self.frame = None |
197 | 229 |
else: |
230 |
f = self.frame |
|
231 |
self.frame = self.pageTemplate.frames[self.pageTemplate.frames.index(f) + 1] |
|
232 |
self.handle_frameBegin() |
|
233 |
||
234 |
def handle_nextPageTemplate(self,pt): |
|
235 |
'''On endPage chenge to the page template with name or index pt''' |
|
236 |
if type(pt) is StringType: |
|
237 |
for t in self.pageTemplates: |
|
238 |
if t.id == pt: |
|
239 |
self._nextPageTemplateIndex = self.pageTemplates.index(t) |
|
240 |
return |
|
241 |
raise ValueError, "can't find template('%s')"%pt |
|
242 |
elif type(pt) is IntType: |
|
243 |
self._nextPageTemplateIndex = pt |
|
244 |
else: |
|
245 |
raise TypeError, "argument pt should be string or integer" |
|
246 |
||
247 |
def handle_nextFrame(self,fx): |
|
248 |
'''On endFrame chenge to the frame with name or index fx''' |
|
249 |
if type(fx) is StringType: |
|
250 |
for f in self.pageTemplate.frames: |
|
251 |
if f.id == fx: |
|
252 |
self._nextFrameIndex = self.pageTemplate.frames.index(f) |
|
253 |
return |
|
254 |
raise ValueError, "can't find frame('%s')"%fx |
|
255 |
elif type(fx) is IntType: |
|
256 |
self._nextFrameIndex = fx |
|
257 |
else: |
|
258 |
raise TypeError, "argument fx should be string or integer" |
|
259 |
||
260 |
def handle_currentFrame(self,fx): |
|
261 |
'''chenge to the frame with name or index fx''' |
|
262 |
if type(fx) is StringType: |
|
263 |
for f in self.pageTemplate.frames: |
|
264 |
if f.id == fx: |
|
265 |
self._nextFrameIndex = self.pageTemplate.frames.index(f) |
|
266 |
return |
|
267 |
raise ValueError, "can't find frame('%s')"%fx |
|
268 |
elif type(fx) is IntType: |
|
269 |
self._nextFrameIndex = fx |
|
270 |
else: |
|
271 |
raise TypeError, "argument fx should be string or integer" |
|
272 |
||
273 |
def handle_flowable(self,flowables): |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
274 |
'''try to handle one flowable from the front of list flowables.''' |
197 | 275 |
f = flowables[0] |
276 |
del flowables[0] |
|
277 |
||
278 |
if isinstance(f,PageBreak): |
|
279 |
self.handle_pageBreak() |
|
280 |
elif isinstance(f,ActionFlowable): |
|
281 |
f.apply(self) |
|
282 |
else: |
|
283 |
#general case we have to do something |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
284 |
if not self.frame.add(f, self.canv, trySplit=self.allowSplitting): |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
285 |
if self.allowSplitting: |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
286 |
# see if this is a splittable thing |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
287 |
S = self.frame.split(f) |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
288 |
n = len(S) |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
289 |
else: |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
290 |
n = 0 |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
291 |
|
197 | 292 |
if n: |
200 | 293 |
if not self.frame.add(S[0], self.canv, trySplit=0): |
294 |
raise "LayoutError", "splitting error" |
|
295 |
del S[0] |
|
296 |
for f in xrange(n-1): |
|
197 | 297 |
flowables.insert(f,S[f]) # put split flowables back on the list |
298 |
else: |
|
299 |
flowables.insert(0,f) # put the flowable back |
|
300 |
self.handle_frameEnd() |
|
301 |
||
204 | 302 |
#these are provided so that deriving classes can refer to them |
197 | 303 |
_handle_documentBegin = handle_documentBegin |
304 |
_handle_pageBegin = handle_pageBegin |
|
305 |
_handle_pageEnd = handle_pageEnd |
|
306 |
_handle_frameBegin = handle_frameBegin |
|
307 |
_handle_frameEnd = handle_frameEnd |
|
308 |
_handle_flowable = handle_flowable |
|
309 |
_handle_nextPageTemplate = handle_nextPageTemplate |
|
310 |
_handle_currentFrame = handle_currentFrame |
|
311 |
_handle_nextFrame = handle_nextFrame |
|
312 |
||
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
313 |
def _startBuild(self): |
197 | 314 |
self.canv = canvas.Canvas(self.filename) |
315 |
self.handle_documentBegin() |
|
316 |
||
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
317 |
def _endBuild(self): |
197 | 318 |
if self._hanging!=[] and self._hanging[-1] is PageBegin: |
319 |
del self._hanging[-1] |
|
320 |
self.clean_hanging() |
|
321 |
else: |
|
322 |
self.clean_hanging() |
|
323 |
self.handle_pageBreak() |
|
324 |
||
325 |
self.canv.save() |
|
326 |
del self.frame, self.pageTemplate |
|
218
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
327 |
|
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
328 |
def build(self, flowables): |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
329 |
assert filter(lambda x: not isinstance(x,Flowable), flowables)==[], "flowables argument error" |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
330 |
self._startBuild() |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
331 |
|
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
332 |
while len(flowables): |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
333 |
self.clean_hanging() |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
334 |
self.handle_flowable(flowables) |
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
335 |
|
274db2129c04
Fixes/Changes to get testplatypus to work with new framework
rgbecker
parents:
214
diff
changeset
|
336 |
self._endBuild() |
221 | 337 |
|
338 |
class SimpleDocTemplate(BaseDocTemplate): |
|
339 |
def handle_pageBegin(self): |
|
340 |
self._handle_pageBegin() |
|
341 |
self._handle_nextPageTemplate('Later') |
|
342 |
||
343 |
def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing): |
|
227 | 344 |
frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal') |
221 | 345 |
self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage), |
346 |
PageTemplate(id='Later',frames=frameT, onPage=onLaterPages)]) |
|
225 | 347 |
if onFirstPage is _doNothing and hasattr(self,'onFirstPage'): |
348 |
self.pageTemplates[0].drawPage = self.onFirstPage |
|
349 |
if onLaterPages is _doNothing and hasattr(self,'onLaterPages'): |
|
350 |
self.pageTemplates[1].drawPage = self.onLaterPages |
|
221 | 351 |
BaseDocTemplate.build(self,flowables) |
352 |
||
353 |
if __name__ == '__main__': |
|
354 |
########################################################## |
|
355 |
## |
|
356 |
## testing |
|
357 |
## |
|
358 |
########################################################## |
|
359 |
def randomText(): |
|
360 |
#this may or may not be appropriate in your company |
|
361 |
from random import randint, choice |
|
362 |
||
363 |
RANDOMWORDS = ['strategic','direction','proactive', |
|
364 |
'reengineering','forecast','resources', |
|
365 |
'forward-thinking','profit','growth','doubletalk', |
|
366 |
'venture capital','IPO'] |
|
367 |
||
368 |
sentences = 5 |
|
369 |
output = "" |
|
370 |
for sentenceno in range(randint(1,5)): |
|
371 |
output = output + 'Blah' |
|
372 |
for wordno in range(randint(10,25)): |
|
373 |
if randint(0,4)==0: |
|
374 |
word = choice(RANDOMWORDS) |
|
375 |
else: |
|
376 |
word = 'blah' |
|
377 |
output = output + ' ' +word |
|
378 |
output = output+'.' |
|
379 |
return output |
|
380 |
||
381 |
def myFirstPage(canvas, doc): |
|
382 |
canvas.saveState() |
|
383 |
canvas.setStrokeColor(red) |
|
384 |
canvas.setLineWidth(5) |
|
385 |
canvas.line(66,72,66,PAGE_HEIGHT-72) |
|
386 |
canvas.setFont('Times-Bold',24) |
|
387 |
canvas.drawString(108, PAGE_HEIGHT-108, "PLATYPUS") |
|
388 |
canvas.setFont('Times-Roman',12) |
|
389 |
canvas.drawString(4 * inch, 0.75 * inch, "First Page") |
|
390 |
canvas.restoreState() |
|
391 |
||
392 |
def myLaterPages(canvas, doc): |
|
393 |
canvas.saveState() |
|
394 |
canvas.setStrokeColor(red) |
|
395 |
canvas.setLineWidth(5) |
|
396 |
canvas.line(66,72,66,PAGE_HEIGHT-72) |
|
397 |
canvas.setFont('Times-Roman',12) |
|
398 |
canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page) |
|
399 |
canvas.restoreState() |
|
400 |
||
401 |
def run(): |
|
402 |
objects_to_draw = [] |
|
403 |
from reportlab.lib.styles import ParagraphStyle |
|
404 |
from paragraph import Paragraph |
|
225 | 405 |
from doctemplate import SimpleDocTemplate |
221 | 406 |
|
407 |
#need a style |
|
408 |
normal = ParagraphStyle('normal') |
|
409 |
normal.firstLineIndent = 18 |
|
410 |
normal.spaceBefore = 6 |
|
411 |
import random |
|
412 |
for i in range(15): |
|
413 |
height = 0.5 + (2*random.random()) |
|
414 |
box = XBox(6 * inch, height * inch, 'Box Number %d' % i) |
|
415 |
objects_to_draw.append(box) |
|
416 |
para = Paragraph(randomText(), normal) |
|
417 |
objects_to_draw.append(para) |
|
418 |
||
419 |
SimpleDocTemplate('doctemplate.pdf',DEFAULT_PAGE_SIZE).build(objects_to_draw, |
|
420 |
onFirstPage=myFirstPage,onLaterPages=myLaterPages) |
|
421 |
||
422 |
run() |