From: Georg Baum Date: Sat, 14 Feb 2015 09:37:32 +0000 (+0100) Subject: Add low-res pdf export as suggested by James X-Git-Tag: 2.1.4~219 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7b53735bb3b0d351df00cf8ea6536670becdd68b;p=features.git 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). --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 09c179bd89..aa813dec57 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2106,6 +2106,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 f72f0a659c..045d8c188e 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" @@ -860,9 +861,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)) diff --git a/status.21x b/status.21x index 9ea7294afc..a8da9d48e0 100644 --- a/status.21x +++ b/status.21x @@ -28,6 +28,8 @@ What's new * DOCUMENT INPUT/OUTPUT +- Add low-resolution PDF export format (needs an installed ghostscript). + * TEX2LYX IMPROVEMENTS