]> git.lyx.org Git - features.git/commitdiff
Add low-res pdf export as suggested by James
authorGeorg Baum <baum@lyx.org>
Wed, 11 Feb 2015 21:24:04 +0000 (22:24 +0100)
committerGeorg Baum <baum@lyx.org>
Wed, 11 Feb 2015 21:24:04 +0000 (22:24 +0100)
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
lib/configure.py
lib/scripts/convert_pdf.py [new file with mode: 0644]

index f70cb854eb2dad9f9b940f640de97809b557d841..802949e3cc015ffde600275ceba494b0b67df2c0 100644 (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 \
index 82071dd1be70e883c2ffeec07b3340aab821d023..595180da65d1d8ec947dca479b3824daf1f7ecad 100644 (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        "%%" ""' ])
diff --git a/lib/scripts/convert_pdf.py b/lib/scripts/convert_pdf.py
new file mode 100644 (file)
index 0000000..e199625
--- /dev/null
@@ -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))