2
# -*- coding: utf-8 -*-
4
# Copyright 2013 by Elena Grandi <elena.valhalla@gmail.com>
5
# Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
Generate test PDF documents for pdfposter.
23
This generates a PDF-file containing a portrait and a landscape page,
27
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
28
__copyright__ = "Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
29
__licence__ = "GNU General Public License version 3 (GPL v3)"
31
from reportlab.lib.units import mm
32
from reportlab.lib.colors import black
33
from reportlab.lib.pagesizes import A4
34
from reportlab.pdfgen.canvas import Canvas
36
def draw_numbers(canvas, numbers, size, margin, rows, cols):
37
step_x = (size[0] - margin*2)/cols
38
step_y = (size[1] - margin*2)/rows
39
for i, n in enumerate(numbers):
40
canvas.drawCentredString(margin + step_x / 2 + step_x * (i%cols),
41
margin + step_y / 2 + ( rows - 1 - i / cols) * step_y, n)
43
def genTestFile(filename):
45
numbers = ['1', '2', '3', '4', '5', '6']
48
#----------- generate the PDF -----------
50
canv = Canvas(filename, pagesize=size)
51
canv.setFont("Helvetica", 72)
52
canv.setStrokeColor(black)
55
draw_numbers(canv,numbers,size,margin,3,2)
56
canv.rect(margin, margin, size[0] - margin * 2,
57
size[1] - margin * 2, fill=0, stroke=1)
62
# second page (landscape)
63
size = (size[1],size[0])
64
canv.setPageSize(size)
65
canv.setFont("Helvetica", 72)
66
canv.setStrokeColor(black)
69
draw_numbers(canv,numbers,size,margin,2,3)
70
canv.rect(margin, margin, size[0] - margin * 2,
71
size[1] - margin * 2, fill=0, stroke=1)
73
# close page, save PDF
78
if __name__ == '__main__':
80
parser = argparse.ArgumentParser()
81
parser.add_argument('filename',
82
help='Name of output file')
83
args = parser.parse_args()
84
genTestFile(args.filename)