From 70afbc82ac463b6030952db6fd229045ef9e7297 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Wed, 11 Feb 2015 22:24:04 +0100 Subject: [PATCH] Add low-res pdf export as suggested by James As discussed on the list, but I did not need to create two new pdf formats since any given document either uses TeX fonts or not. For the same reason I also added an additional converter to PDF (cropped). --- lib/Makefile.am | 1 + lib/configure.py | 16 +++++++++--- lib/scripts/convert_pdf.py | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 lib/scripts/convert_pdf.py diff --git a/lib/Makefile.am b/lib/Makefile.am index f70cb854eb..802949e3cc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2124,6 +2124,7 @@ dist_scripts_DATA = \ # Note that we "chmod 755" manually these files in install-data-hook. dist_scripts_DATA += \ scripts/clean_dvi.py \ + scripts/convert_pdf.py \ scripts/convertDefault.py \ scripts/csv2lyx.py \ scripts/date.py \ diff --git a/lib/configure.py b/lib/configure.py index 82071dd1be..595180da65 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -661,7 +661,8 @@ def checkFormatEntries(dtl_tools): \Format pdf4 pdf "PDF (XeTeX)" X "%%" "" "document,vector,menu=export" "" \Format pdf5 pdf "PDF (LuaTeX)" u "%%" "" "document,vector,menu=export" "" \Format pdf6 pdf "PDF (graphics)" "" "%%" "" "vector" "application/pdf" -\Format pdf7 pdf "PDF (cropped)" "" "%%" "" "document,menu=export" ""''']) +\Format pdf7 pdf "PDF (cropped)" "" "%%" "" "document,vector,menu=export" "" +\Format pdf8 pdf "PDF (150 dpi)" "" "%%" "" "document,vector,menu=export" ""''']) # checkViewer('a DVI previewer', ['xdvi', 'kdvi', 'okular', 'yap', 'dviout -Set=!m'], rc_entry = [r'''\Format dvi dvi DVI D "%%" "" "document,vector,menu=export" "application/x-dvi" @@ -861,9 +862,18 @@ def checkConverterEntries(): # Only define a converter from pdf6 for graphics checkProg('a PDF to EPS converter', ['pdftops -eps -f 1 -l 1 $$i $$o'], rc_entry = [ r'\converter pdf6 eps "%%" ""' ]) - # + # Create one converter for a PDF produced using TeX fonts and one for a + # PDF produced using non-TeX fonts. This does not produce non-unique + # conversion paths, since a given document either uses TeX fonts or not. checkProg('a PDF cropping tool', ['pdfcrop $$i $$o'], - rc_entry = [ r'\converter pdf2 pdf7 "%%" ""' ]) + rc_entry = [ r'''\converter pdf2 pdf7 "%%" ""' ]) +\converter pdf4 pdf7 "%%" ""''' ]) + # Create one converter for a PDF produced using TeX fonts and one for a + # PDF produced using non-TeX fonts. This does not produce non-unique + # conversion paths, since a given document either uses TeX fonts or not. + checkProg('Ghostscript', ["gswin32c", "gswin64c", "gs"], + rc_entry = [ r'''\converter pdf2 pdf8 "python -tt $$s/scripts/convert_pdf.py $$i $$o ebook" "" +\converter pdf4 pdf8 "python -tt $$s/scripts/convert_pdf.py $$i $$o ebook" ""''' ]) # checkProg('a Beamer info extractor', ['makebeamerinfo -p $$i'], rc_entry = [ r'\converter pdf2 beamer.info "%%" ""' ]) diff --git a/lib/scripts/convert_pdf.py b/lib/scripts/convert_pdf.py new file mode 100644 index 0000000000..e1996259f1 --- /dev/null +++ b/lib/scripts/convert_pdf.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# file convert_pdf.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. + +# author Georg Baum +# Full author contact details are available in file CREDITS + +# This script takes a PS or PDF file and creates a low resolution version. +# Example usage: +# convert_pdf.py big.pdf small.pdf ebook + +# This script takes three arguments: +# INFILE: the name of the .ps or .pdf file to be converted. +# OUTFILE: the name of the .pdf file to be created. +# PDFSETTINGS: any PDFSETTINGS supported by ghostscript: + + +import sys + +from lyxpreview_tools import error, find_exe_or_terminate, run_command + + +def usage(prog_name): + return "Usage: %s " \ + % prog_name + + +def main(argv): + + if len(argv) == 4: + source = argv[1] + output = argv[2] + pdfsettings = argv[3] + else: + error(usage(argv[0])) + + gs = find_exe_or_terminate(["gswin32c", "gswin64c", "gs"]) + gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite ' \ + '-dCompatibilityLevel=1.4 -dPDFSETTINGS=/%s ' \ + '-sOutputFile="%s" "%s"' % (gs, pdfsettings, output, source) + + gs_status, gs_stdout = run_command(gs_call) + if gs_stdout: + sys.stdout.write(gs_stdout) + return gs_status + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) -- 2.39.2