Skip to content

Commit

Permalink
Added three small helper scripts, versions to pandoc
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Feb 5, 2018
1 parent 95e0a96 commit 38644c5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ We also provide some utility scripts for working with `PDF`, `PS`, and `EPS` fil

- `eps2pdf.sh <document>` convert the `EPS` file `<document>` to `PDF`
- `filterPdf.sh <document>` transform a document (either in [PostScript](https://en.wikipedia.org/wiki/PostScript)/`PS`, `EPS`, or `PDF` format) to `PDF` and include as many of the fonts used inside the document into the final `PDF`. This allows to produce a `PDF` from a `.ps` file `<document>` which should display correctly on as many computers as possible.
- `filterPdfExact.sh <document>` does the same as `filderPdf.sh`, except that it does not re-encode the included images.
- `sudo` is a pseudo-`sudo` command: Inside a Docker container, we don't need `sudo`. However, if you have a script or something that calls plain `sudo` (without additional arguments) just with a to-be-sudoed command, this script will emulate a `sudo`. By doing nothing.
- `downscalePdf.sh <document> {resolution}` makes a pdf document smaller by downscaling all included images (to the specified resolution).
- `findNonASCIIChars.sh <document>` finds non-ASCII characters in a document. In `.tex` documents, such characters may pose problems.

## 4. License

Expand Down
4 changes: 2 additions & 2 deletions image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ RUN export LANG=C.UTF-8 &&\
texlive-science=2015.2016* \
texlive-xetex=2015.2016* &&\
# install pandoc
apt-get install -f -y pandoc \
pandoc-citeproc &&\
apt-get install -f -y pandoc=1.16*\
pandoc-citeproc=0.9* &&\
# free huge amount of unused space
apt-get purge -f -y make-doc \
texlive-fonts-extra-doc \
Expand Down
58 changes: 58 additions & 0 deletions image/scripts/downscalePdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash


# Make a pdf File Smaller by downscaling all included images

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialized variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value


echo "Make a pdf File Smaller by downscaling all included images."

source="$1"
name="${source%%.*}"
dest="$name.pdf"

if [ -f "$dest" ]; then
useSource="$name.original.pdf"
echo "Creating backup '$useSource' of '$dest'."
cp "$dest" "$useSource"
else
useSource="$source"
fi

resolution=${2:-}

if [[ -n "$resolution" ]]
then
echo "The resolution '$resolution' was specified."
else
resolution=192
echo "No resolution was specified, using '$resolution'."
fi

echo "Downscaling '$useSource' to '$dest'."

gs -q -dEmbedAllFonts=true -dSubsetFonts=true -dCompressFonts=true \
-dOptimize=true \
-dPreserveCopyPage=false -dPreserveEPSInfo=false -dPreserveHalftoneInfo=false \
-dPreserveOPIComments=false -dPreserveOverprintSettings=false \
-dPreserveSeparation=false -dPreserveDeviceN=false \
-dMaxBitmap=2147483647 \
-dDownsampleMonoImages=true -dDownsampleGrayImages=true -dDownsampleColorImages=true \
-dColorImageDownsampleType=/Bicubic -dGrayImageDownsampleType=/Bicubic \
-dMonoImageDownsampleType=/Bicubic \
-dColorImageResolution=$resolution -dGrayImageResolution=$resolution -dMonoImageResolution=$resolution \
-dFastWebView=false \
-dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite -dAutoRotatePages=/PageByPage \
-sOutputFile="$dest" "$useSource" \
-c .setpdfwrite "<</NeverEmbed [ ]>> setdistillerparams"


chmod 777 "$dest" || true

echo "Finished creating downsampled, smaller version."

15 changes: 15 additions & 0 deletions image/scripts/filterPdfExact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -

# This script filters a PDF file and attempts to include
# as many fonts as possible. It works like filterPdf, but
# avoids image re-encoding.

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialized variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

"$scriptDir/__filterPdf.sh" "$1" "-dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dColorConversionStrategy=/LeaveColorUnchanged"
10 changes: 10 additions & 0 deletions image/scripts/findNonASCIIChars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialized variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

# Find non-ASCII characters which may cause problems in tex documents.
grep --color='auto' -P -n '[^\x00-\x7F]' "$1"

0 comments on commit 38644c5

Please sign in to comment.