{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ReportLab A0 Canvas\n", "\n", "Using loops and variables to create an A0 grid...\n", "\n", "\n", "\n", "[line](https://www.reportlab.com/docs/reportlab-userguide.pdf#page=13)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from reportlab.pdfgen.canvas import Canvas\n", "from reportlab.lib.pagesizes import A4, A0\n", "from reportlab.lib.units import inch, cm, mm\n", "import sys\n", "from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "c = Canvas(\"grid.pdf\", pagesize=A0)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "draw a line segment from (x1,y1) to (x2,y2) (with color, thickness and\n", "other attributes determined by the current graphics state).\n", "\u001b[0;31mFile:\u001b[0m /opt/tljh/user/lib/python3.7/site-packages/reportlab/pdfgen/canvas.py\n", "\u001b[0;31mType:\u001b[0m method\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "c.line?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msetLineWidth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwidth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m \n", "\u001b[0;31mFile:\u001b[0m /opt/tljh/user/lib/python3.7/site-packages/reportlab/pdfgen/canvas.py\n", "\u001b[0;31mType:\u001b[0m method\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "c.setLineWidth?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "c.line(0, 0, 100, 200)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "c.setLineWidth(3*mm)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "c.line(0, 0, 200, 100)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(2383.937007874016, 3370.393700787402)\n", "595.984251968504\n" ] } ], "source": [ "pagew, pageh = A0\n", "colw = pagew/4\n", "print (A0)\n", "print (colw)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "for x in range(4):\n", " c.line(x*colw, 0, x*colw, pageh)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "842.5984251968505\n" ] } ], "source": [ "colh = pageh/4\n", "print (colh)\n", "for y in range(4):\n", " c.line(0, y*colh, pagew, y*colh)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "c.showPage()\n", "c.save()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }