Search code examples
pythonreportlab

How to change the x, y start point for drawing a table in reportlab python?


I'm trying to draw a dymanic table (length is variable depending on when its executed).

My code is as follows:

basicData = [['\nDate\n', '\n' + date + '\n'],
        ['\nLaunch Time\n', '\n' + launch + '\n']]

basicDTable = Table(basicData)

basicDTable.setStyle(TableStyle([('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                                 ('BOX', (0, 0), (-1, -1), 0.25, colors.black),
                                 ('FONTSIZE', (0, 0), (-1, -1), 12),
                                 ('FONT', (0, 0), (0, 2), 'Times-Bold')]))
                       
basicDTable.wrapOn(canvas,100,100)

basicDTable.drawOn(canvas, 175, 300) 

Is there any way when using the drawOn function, that (x, y) could be the coordinates of the top left point opposed to the bottom left?

Thanks in advance for any help or advice.


Solution

  • Canvas objects have a "translate" method that moves the origin by the given coordinates. The syntax is canvas.translate(x, y). The origin is then moved by x and y.

    If you want to move the origin from bottom left to the top left, you can simply set x to 0 and y to the height of your document.