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).
This commit is contained in:
Georg Baum 2015-02-11 22:24:04 +01:00
parent b2c761a7db
commit 70afbc82ac
3 changed files with 65 additions and 3 deletions

View File

@ -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 \

View File

@ -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 "%%" ""' ])

View File

@ -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 <ps or pdf input file> <pdf output file> <screen|ebook|printer|prepress>" \
% 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))