fix cross-device link error
[PyX.git] / contrib / dviconvert.py
blobaf6f9e5539803ef2a9cd44dafe30e941d1e6e9eb
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
5 # Copyright (C) 2005-2011 André Wobst <wobsta@users.sourceforge.net>
7 # dviconvert 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 2 of the License, or
10 # (at your option) any later version.
12 # epstopng is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with epstopng; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 from optparse import OptionParser
22 from pyx import *
23 from pyx import bbox, version
24 from pyx.dvi import dvifile
26 parser = OptionParser(usage="usage: %prog [-b] [-p paperformat] -o output-file dvi-file",
27 version="%prog " + version.version)
28 parser.add_option("-o", "--output",
29 type="string", dest="output",
30 help="output-file")
31 parser.add_option("-p", "--paperformat",
32 type="string", dest="paperformat", default=None,
33 help="optional paper format string")
34 parser.add_option("-b", "--writebbox",
35 action="store_true", dest="writebbox", default=0,
36 help="Add bouding box information on PS and PDF when a paperformat is defined")
37 (options, args) = parser.parse_args()
38 if len(args) != 1:
39 parser.error("can process a single dvi-file only")
41 if options.paperformat:
42 options.paperformat = getattr(document.paperformat, options.paperformat)
43 df = dvifile.DVIfile(args[0])
44 d = document.document()
45 while 1:
46 dvipage = df.readpage()
47 if not dvipage:
48 break
49 if options.paperformat:
50 aligntrafo = trafo.translate(unit.t_inch, -unit.t_inch + options.paperformat.height)
51 aligneddvipage = canvas.canvas([aligntrafo])
52 aligneddvipage.insert(dvipage)
53 p = document.page(aligneddvipage, paperformat=options.paperformat, centered=0)
54 else:
55 p = document.page(dvipage)
56 d.append(p)
57 if options.writebbox:
58 d.writetofile(options.output)
59 else:
60 d.writetofile(options.output, writebbox=1)