diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-09-29 23:54:06 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-29 23:54:06 -0600 |
| commit | a52472cad381390c54070fc81da19fb0c0bec48f (patch) | |
| tree | ae564529fe80e6e53123e06117c7fea722d59b7d /bin | |
| parent | cd72c55a1fd3261889c8820736126da4ea2caa7a (diff) | |
resolves #535 optimize PDF if writing file and optimize attribute is set (PR #1299)
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/asciidoctor-pdf-optimize | 20 | ||||
| -rwxr-xr-x | bin/optimize-pdf | 65 |
2 files changed, 20 insertions, 65 deletions
diff --git a/bin/asciidoctor-pdf-optimize b/bin/asciidoctor-pdf-optimize new file mode 100755 index 00000000..744dd8ec --- /dev/null +++ b/bin/asciidoctor-pdf-optimize @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +optimizer = File.absolute_path '../lib/asciidoctor-pdf/optimizer.rb', __dir__ +if File.exist? optimizer + require optimizer +else + require 'asciidoctor-pdf/optimizer' +end + +args = ARGV.dup + +unless (filename = args.pop) + warn 'optimize-pdf: Please specify a PDF file to optimize.' + exit 1 +end + +quality = args[0] == '-q' ? args[1].to_s : '' + +(Asciidoctor::PDF::Optimizer.new quality).generate_file filename diff --git a/bin/optimize-pdf b/bin/optimize-pdf deleted file mode 100755 index 6cc71ab8..00000000 --- a/bin/optimize-pdf +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# Optimizes and compresses the specified PDF using Ghostscript (gs). -# -# [NOTE] -# You need at least Ghostscript 9.10 in order for page labels defined in the -# PDF to be preserved (e.g., front matter pages numbered using roman numerals). - -if [ -z $1 ]; then - echo "Please supply a PDF file to optimize" - exit 1 -fi - -if [ -z $GS ]; then - GS=gs -fi - -FILE=$1 -FILE_BASENAME=${FILE%.pdf} -FILE_OPTIMIZED=$FILE_BASENAME-optimized.pdf -FILE_PDFMARK= -if [ -f "$FILE_BASENAME.pdfmark" ]; then - FILE_PDFMARK="$FILE_BASENAME.pdfmark" -fi -DOWNSAMPLE_IMAGES=true -if [ -z $IMAGE_DPI ]; then - #IMAGE_DPI=150 - IMAGE_DPI=300 -fi - -# /prepress defaults (see http://ghostscript.com/doc/current/Ps2pdf.htm) -# -d{Color,Gray,Mono}ImageDownsampleType=/Bicubic -# -dAutoFilter{Color,Gray}Images=true -# -dOptimize=true -# -dEmbedAllFonts=true -# -dSubsetFonts=true -# -dColorConversionStrategy=/LeaveColorUnchanged -# -dUCRandBGInfo=/Preserve -# -dCompressPages=true -# -# other unused settings -# -r72 -# -# for info about pdfmarks, see http://milan.kupcevic.net/ghostscript-ps-pdf -# -# to convert to grayscale, add the following (though doesn't always work) -# -# -dProcessColorModel=/DeviceGray \ -# -dColorConversionStrategy=/Gray \ - -"$GS" -q -dNOPAUSE -dBATCH -dSAFER -dNOOUTERSAVE \ - -sDEVICE=pdfwrite \ - -dPDFSETTINGS=/prepress \ - -dPrinted=false \ - -dCannotEmbedFontPolicy=/Warning \ - -dDownsampleColorImages=$DOWNSAMPLE_IMAGES \ - -dColorImageResolution=$IMAGE_DPI \ - -dDownsampleGrayImages=$DOWNSAMPLE_IMAGES \ - -dGrayImageResolution=$IMAGE_DPI \ - -dDownsampleMonoImages=$DOWNSAMPLE_IMAGES \ - -dMonoImageResolution=$IMAGE_DPI \ - -sOutputFile="$FILE_OPTIMIZED" \ - "$FILE" $FILE_PDFMARK - -exit 0 |
