from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import A4 from reportlab.lib.units import mm c = canvas.Canvas("hello.pdf", pagesize=A4) width, height = A4 numv = int((width - ((4 + 4) * mm)) / (5 * mm)) numh = int((height / 2.0 - ((12.5 + 2) * mm)) / (5 * mm)) voff = (width - numv * 5 * mm) / 2.0 hoff = height / 2 - (12.5 + numh * 5) * mm # Draw grid c.setLineWidth(0.15) c.setStrokeColorRGB(0.5, 0.5, 1) for xi in xrange(numv + 1): c.line(xi * mm * 5 + voff, hoff, xi * mm * 5 + voff, hoff + numh * mm * 5) c.line(xi * mm * 5 + voff, height - hoff, xi * mm * 5 + voff, height - (hoff + numh * mm * 5)) for yi in xrange(numh + 1): c.line(voff, hoff + yi * mm * 5, voff + numv * mm * 5, hoff + yi * mm * 5) c.line(voff, height - (hoff + yi * mm * 5), voff + numv * mm * 5, height - (hoff + yi * mm * 5)) # Draw horizontal center c.setDash(1) c.setStrokeColorRGB(0.5, 0.5, 1) c.circle(width / 2, height / 2 + 1.5 * mm, 0.5, fill=1) c.circle(width / 2, height / 2 - 1.5 * mm, 0.5, fill=1) # Draw splitter c.setDash([3, 3]) c.setStrokeColorRGB(0.4, 0.4, 0.4) c.line(0, height / 2, width, height / 2) c.save()