]> git.lyx.org Git - lyx.git/blob - lib/scripts/convert_pdf.py
DocBook: update links to LilyPond bugs.
[lyx.git] / lib / scripts / convert_pdf.py
1 # -*- coding: utf-8 -*-
2
3 # file convert_pdf.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6
7 # author Georg Baum
8 # Full author contact details are available in file CREDITS
9
10 # This script takes a PS or PDF file and creates a low resolution version.
11 # Example usage:
12 # convert_pdf.py big.pdf small.pdf ebook
13
14 # This script takes three arguments:
15 # INFILE:        the name of the .ps or .pdf file to be converted.
16 # OUTFILE:       the name of the .pdf file to be created.
17 # PDFSETTINGS:   any PDFSETTINGS supported by ghostscript:
18
19
20 import sys
21
22 from lyxpreview_tools import error, find_exe_or_terminate, run_command
23
24
25 def usage(prog_name):
26     return "Usage: %s <ps or pdf input file> <pdf output file> <screen|ebook|printer|prepress>" \
27         % prog_name
28
29
30 def main(argv):
31
32     if len(argv) == 4:
33         source = argv[1]
34         output = argv[2]
35         pdfsettings = argv[3]
36     else:
37         error(usage(argv[0]))
38
39     gs = find_exe_or_terminate(["gswin32c", "gswin64c", "gs"])
40     gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite ' \
41               '-dCompatibilityLevel=1.4 -dPDFSETTINGS=/%s ' \
42               '-sOutputFile="%s" "%s"' % (gs, pdfsettings, output, source)
43
44     gs_status, gs_stdout = run_command(gs_call)
45     if gs_stdout:
46         sys.stdout.write(gs_stdout)
47     return gs_status
48
49
50 if __name__ == "__main__":
51     sys.exit(main(sys.argv))