~ubuntu-branches/ubuntu/utopic/pdfposter/utopic

« back to all changes in this revision

Viewing changes to test/gen-testpages.py

  • Committer: Package Import Robot
  • Author(s): Elena Grandi, Jakub Wilk, Elena Grandi
  • Date: 2013-05-22 10:03:38 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130522100338-26uo6rmqsurfcfzv
Tags: 0.6.0-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Elena Grandi ]
* New upstream release
* Regenerate PDF files from python sources
* Include html documentation
* Updated homepage and author contacts
* debian/control: bump Standards-Version to 3.9.3 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# Copyright 2013 by Elena Grandi <elena.valhalla@gmail.com>
 
5
# Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
"""
 
21
Generate test PDF documents for pdfposter.
 
22
 
 
23
This generates a PDF-file containing a portrait and a landscape page,
 
24
DIN A4.
 
25
"""
 
26
 
 
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)"
 
30
 
 
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
 
35
 
 
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)
 
42
 
 
43
def genTestFile(filename):
 
44
    size = A4
 
45
    numbers = ['1', '2', '3', '4', '5', '6']
 
46
    margin = 20*mm
 
47
 
 
48
    #----------- generate the PDF -----------
 
49
    # 1st page (portrait)
 
50
    canv = Canvas(filename, pagesize=size)
 
51
    canv.setFont("Helvetica", 72)
 
52
    canv.setStrokeColor(black)
 
53
 
 
54
    # draw the content
 
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)
 
58
 
 
59
    # close page
 
60
    canv.showPage()
 
61
 
 
62
    # second page (landscape)
 
63
    size = (size[1],size[0])
 
64
    canv.setPageSize(size)
 
65
    canv.setFont("Helvetica", 72)
 
66
    canv.setStrokeColor(black)
 
67
 
 
68
    # draw the content
 
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)
 
72
 
 
73
    # close page, save PDF
 
74
    canv.showPage()
 
75
    canv.save()
 
76
 
 
77
 
 
78
if __name__ == '__main__':
 
79
    import argparse
 
80
    parser = argparse.ArgumentParser()
 
81
    parser.add_argument('filename',
 
82
                        help='Name of output file')
 
83
    args = parser.parse_args()
 
84
    genTestFile(args.filename)