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

« back to all changes in this revision

Viewing changes to pdftools/pdfposter/cmd.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:
3
3
pdftools.pdfposter.cmd - scale and tile PDF images/pages to print on multiple pages.
4
4
"""
5
5
#
6
 
# Copyright 2008-2009 by Hartmut Goebel <h.goebel@goebel-consult.de>
 
6
# Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>
7
7
#
8
8
# This program is free software: you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
#
21
21
 
22
 
__author__ = "Hartmut Goebel <h.goebel@goebel-consult.de>"
23
 
__copyright__ = "Copyright 2008-2009 by Hartmut Goebel <h.goebel@goebel-consult.de>"
 
22
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
 
23
__copyright__ = "Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
24
24
__licence__ = "GNU General Public License version 3 (GPL v3)"
25
25
 
26
26
from . import main, __version__, DEFAULT_MEDIASIZE, papersizes, DecryptionError
27
27
import re
28
 
from pyPdf.utils import PdfReadError
 
28
import pyPdf.utils
29
29
 
30
30
# pattern for parsing user textual box spec
31
31
pat_box = re.compile(r'''
32
 
     ( (?P<width>  (\d*\.)? \d*) x                 # width "x" height
33
 
       (?P<height> (\d*\.)? \d*) )? 
 
32
     ( (?P<width>  (\d*\.)? \d+) x                 # width "x" height
 
33
       (?P<height> (\d*\.)? \d+) )?
34
34
     (?P<offset> \+                                # "+" offset_x "," offset_y
35
35
                 (?P<offset_x> \d+\.? | \d*\.\d+)
36
36
                 ,
44
44
        raise parser.error("I don't understand your box specification %r for %s" % (value, option))
45
45
    res = m.groupdict()
46
46
    if not allow_offset and res['offset'] is not None:
47
 
        raise parser.errot('Offset not allowed in box definition for %s' % option)
 
47
        raise parser.error('Offset not allowed in box definition for %s' % option)
48
48
    # res['offset'] is only used for error checking, remove it
49
49
    del res['offset']
50
50
 
53
53
    if not papersizes.has_key(unit):
54
54
        unit = [name for name in papersizes.keys()
55
55
                if name.startswith(unit)]
56
 
        if len(unit) != 1:
57
 
            parser.error('Your box spec %r for %s is not unique, give more chars.' % (res['unit'], option))
 
56
        if len(unit) == 0:
 
57
            parser.error("I don't understand your papersize name %r for %s." % (res['unit'], option))
 
58
        elif len(unit) != 1:
 
59
            parser.error('Your papersize name %r for %s is not unique, give more chars.' % (res['unit'], option))
58
60
        unit = unit[0]
59
61
    unit_x, unit_y = papersizes[unit]
60
62
    res2 = {
62
64
        'height'  : float(res['height'] or 1) * unit_y,
63
65
        'offset_x': float(res['offset_x'] or 0) * unit_x,
64
66
        'offset_y': float(res['offset_y'] or 0) * unit_y,
65
 
        'unit': res['unit'],
66
 
        'units_x': res['width'] or 1,
67
 
        'units_y': res['height'] or 1,
 
67
        'unit': unit,
 
68
        'units_x': float(res['width'] or 1),
 
69
        'units_y': float(res['height'] or 1),
68
70
        }
69
71
    return res2
70
72
 
77
79
    parser = optparse.OptionParser('%prog [options] InputFile OutputFile',
78
80
                                   version=__version__)
79
81
    parser.add_option('--help-media-names', action='store_true',
80
 
                      help='List available media and disctance names')
 
82
                      help='List available media and distance names')
81
83
    parser.add_option('-v', '--verbose', action='count', default=0,
82
84
                      help='Be verbose. Tell about scaling, rotation and number of pages. Can be used more than once to increase the verbosity. ')
83
85
    parser.add_option('-n', '--dry-run', action='store_true',
84
86
                      help='Show what would have been done, but do not generate files.')
85
 
    
 
87
 
 
88
    parser.add_option('-A', '--art-box',
 
89
                      action='store_true', dest='use_ArtBox',
 
90
                      help='Use the content area defined by the ArtBox '
 
91
                      '(default: use the area defined by the TrimBox)')
 
92
 
86
93
    group = parser.add_option_group('Define Target')
87
94
    group.add_option('-m', '--media-size',
88
95
                     default=__parse_box('-m', DEFAULT_MEDIASIZE, parser),
100
107
        names = papersizes.keys()
101
108
        names.sort()
102
109
        parser.print_usage()
103
 
        print parser.formatter.format_heading('Avialable media and distance names')
 
110
        print parser.formatter.format_heading('Available media and distance names')
104
111
        parser.formatter.indent()
105
112
        print parser.formatter.format_description(' '.join(names))
106
113
        raise SystemExit(0)
122
129
        main(opts, *args)
123
130
    except DecryptionError, e:
124
131
        raise SystemExit(str(e))
125
 
    except PdfReadError:
126
 
        parser.error('Only well formed PDF files are supported as input.')
 
132
    except pyPdf.utils.PdfReadError:
 
133
        parser.error('The input-file is either currupt or no PDF at all.')
127
134
 
128
135
 
129
136
if __name__ == '__main__':