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.

4.5 KiB

ReportLab A0 Canvas

Using loops and variables to create an A0 grid...

https://www.reportlab.com/docs/reportlab-userguide.pdf#page=10

line

In [1]:
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4, A0
from reportlab.lib.units import inch, cm, mm
import sys
from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics
In [2]:
c = Canvas("grid.pdf", pagesize=A0)
In [3]:
c.line?
Signature: c.line(x1, y1, x2, y2)
Docstring:
draw a line segment from (x1,y1) to (x2,y2) (with color, thickness and
other attributes determined by the current graphics state).
File:      /opt/tljh/user/lib/python3.7/site-packages/reportlab/pdfgen/canvas.py
Type:      method
In [4]:
c.setLineWidth?
Signature: c.setLineWidth(width)
Docstring: <no docstring>
File:      /opt/tljh/user/lib/python3.7/site-packages/reportlab/pdfgen/canvas.py
Type:      method
In [5]:
c.line(0, 0, 100, 200)
In [6]:
c.setLineWidth(3*mm)
In [7]:
c.line(0, 0, 200, 100)
In [8]:
pagew, pageh = A0
colw = pagew/4
print (A0)
print (colw)
(2383.937007874016, 3370.393700787402)
595.984251968504
In [9]:
for x in range(4):
    c.line(x*colw, 0, x*colw, pageh)
In [10]:
colh = pageh/4
print (colh)
for y in range(4):
    c.line(0, y*colh, pagew, y*colh)
842.5984251968505
In [11]:
c.showPage()
c.save()
In [ ]: