File: gen-examplepages.py

package info (click to toggle)
pdfposter 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 808 kB
  • sloc: python: 1,354; makefile: 45; sh: 40
file content (89 lines) | stat: -rw-r--r-- 3,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2008-2025 by Hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright 2013 by Elena Grandi <elena.valhalla@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Generate example PDF documents for pdfposter.

This generates two PDF-files:
- a tall one (5.0 cm x 29,7 cm)
- a wide one (29.7 cm x 5.0 cm)

These pages are later used creating images for examples.
"""

__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2008-2025 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__license__ = "GPL-3.0-or-later"

from reportlab.lib.units import mm
from reportlab.lib.colors import black
from reportlab.pdfgen.canvas import Canvas

def genTestFile(filename_tall, filename_wide):
    short_size = 50*mm
    long_size = 297*mm
    numbers = ['B', 'A', '9', '8', '7', '6', '5', '4', '3', '2', '1']
    margin = 10*mm

    #----------- generate the tall PDF -----------
    size = (short_size, long_size)
    step = (long_size - margin*2)/len(numbers)
    canv = Canvas(filename_tall, pagesize=size)
    canv.setFont("Helvetica", 72)
    canv.setStrokeColor(black)

    # draw the content
    for i, n in enumerate(numbers):
        canv.drawCentredString(short_size/2, step*i + margin + 4*mm, n)
    canv.rect(margin, margin, short_size - margin * 2,
            long_size - margin * 2, fill=0, stroke=1)

    # save the pdf file
    canv.showPage()
    canv.save()

    #----------- generate the wide PDF -----------
    size = (long_size, short_size)
    step = (long_size - margin*2)/len(numbers)
    numbers.reverse()
    canv = Canvas(filename_wide, pagesize=size)
    canv.setFont("Helvetica", 72)
    canv.setStrokeColor(black)

    # draw the contents
    for i, n in enumerate(numbers):
        canv.drawCentredString(step*i + margin + step/2, margin + 6*mm, n)
    canv.rect(margin, margin, long_size - margin * 2,
            short_size - margin * 2, fill=0, stroke=1)

    # save the pdf file
    canv.showPage()
    canv.save()


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('filename_tall',
                        help='Name of tall output file')
    parser.add_argument('filename_wide',
                        help='Name of wide output file')
    args = parser.parse_args()
    genTestFile(args.filename_tall, args.filename_wide)