~ubuntu-branches/ubuntu/vivid/python-reportlab/vivid-proposed

« back to all changes in this revision

Viewing changes to src/reportlab/graphics/renderPDF.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-01-12 02:16:21 UTC
  • mfrom: (1.2.9) (4.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140112021621-f4mpp5qaj1dkq2yb
Tags: 2.8~20140112-1
* New upstream snapshot.
* Build python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/renderPDF.py
4
4
# renderPDF - draws Drawings onto a canvas
5
5
 
6
 
__version__=''' $Id: renderPDF.py 3959 2012-09-27 14:39:39Z robin $ '''
 
6
__version__=''' $Id$ '''
7
7
__doc__="""Render Drawing objects within others PDFs or standalone
8
8
 
9
9
Usage::
18
18
from reportlab.graphics.shapes import *
19
19
from reportlab.pdfgen.canvas import Canvas
20
20
from reportlab.pdfbase.pdfmetrics import stringWidth
21
 
from reportlab.lib.utils import getStringIO
 
21
from reportlab.lib.utils import getBytesIO
22
22
from reportlab import rl_config
23
 
from renderbase import Renderer, StateTracker, getStateDelta, renderScaledDrawing
 
23
from reportlab.graphics.renderbase import Renderer, StateTracker, getStateDelta, renderScaledDrawing
24
24
 
25
25
# the main entry point for users...
26
26
def draw(drawing, canvas, x, y, showBoundary=rl_config._unset_):
165
165
                elif text_anchor=='numeric':
166
166
                    x -= numericXShift(text_anchor,text,textLen,font,font_size,enc)
167
167
                else:
168
 
                    raise ValueError, 'bad value for textAnchor '+str(text_anchor)
 
168
                    raise ValueError('bad value for textAnchor '+str(text_anchor))
169
169
            t = self._canvas.beginText(x,y)
170
170
            t.textLine(text)
171
171
            self._canvas.drawText(t)
303
303
 
304
304
def drawToString(d, msg="", showBoundary=rl_config._unset_,autoSize=1):
305
305
    "Returns a PDF as a string in memory, without touching the disk"
306
 
    s = getStringIO()
 
306
    s = getBytesIO()
307
307
    drawToFile(d, s, msg=msg, showBoundary=showBoundary,autoSize=autoSize)
308
308
    return s.getvalue()
309
309
 
313
313
#   Routine to draw them comes at the end.
314
314
#
315
315
#########################################################
316
 
def test():
 
316
def test(outDir='pdfout',shout=False):
317
317
    from reportlab.graphics.shapes import _baseGFontName, _baseGFontNameBI
318
 
    c = Canvas('renderPDF.pdf')
 
318
    from reportlab.rl_config import verbose
 
319
    import os
 
320
    if not os.path.isdir(outDir):
 
321
        os.mkdir(outDir)
 
322
    fn = os.path.join(outDir,'renderPDF.pdf')
 
323
    c = Canvas(fn)
319
324
    c.setFont(_baseGFontName, 36)
320
325
    c.drawString(80, 750, 'Graphics Test')
321
326
 
356
361
    if y!=740: c.showPage()
357
362
 
358
363
    c.save()
359
 
    print 'saved renderPDF.pdf'
 
364
    if shout or verbose>2:
 
365
        print('saved %s' % ascii(fn))
360
366
 
361
367
##def testFlowable():
362
368
##    """Makes a platypus document"""
385
391
##    print 'saves test_flowable.pdf'
386
392
 
387
393
if __name__=='__main__':
388
 
    test()
 
394
    test(shout=True)
 
395
    import sys
 
396
    if len(sys.argv)>1:
 
397
        outdir = sys.argv[1]
 
398
    else:
 
399
        outdir = 'pdfout'
 
400
    test(outdir,shout=True)
389
401
    #testFlowable()