Skip to content

Instantly share code, notes, and snippets.

@jfrost
Last active July 22, 2016 17:28
Show Gist options
  • Save jfrost/a4a3501418997f3bc5fd048c5b5e03e8 to your computer and use it in GitHub Desktop.
Save jfrost/a4a3501418997f3bc5fd048c5b5e03e8 to your computer and use it in GitHub Desktop.
Script to package pdf2htmlex with fontforge and poppler
#!/bin/bash
#
# Based on: https://gist.github.com/rajeevkannav/d07f822e209a22d07176
POPPLER_VERSION=$1
# second argument is the pdf2htmlEX version
# default to 0.14.6
PDF2HTMLEX_VERSION=${2:-"0.14.6"}
if [ "${POPPLER_VERSION}" = "" ]; then
echo "Please provide a Poppler version"
exit 1
fi
HOME_PATH=$(cd ~/ && pwd)
POPPLER_SOURCE="http://poppler.freedesktop.org/poppler-${POPPLER_VERSION}.tar.xz"
FONTFORGE_SOURCE="https://github.com/fontforge/fontforge/releases/download/20160404/fontforge-20160404.tar.gz"
PDF2HTMLEX_SOURCE="https://github.com/coolwanglu/pdf2htmlEX.git"
PDF2HTMLEX_PKG="pdf2htmlex_poppler_fontforge_${PDF2HTMLEX_VERSION}_amd64.deb"
INSTALLDIR="$(mktemp -d /tmp/pdf2htmlex.XXXXXXXXXXXX)"
echo "Updating all Ubuntu software repository lists ..."
apt-get update
echo "Installing basic dependencies ..."
apt-get install -qq -y cmake gcc libgetopt++-dev git
echo "Installing Poppler dependecies ..."
apt-get install -qq -y pkg-config libopenjpeg-dev libfontconfig1-dev libfontforge-dev
echo "Installing fpm ..."
gem install fpm
echo "Downloading poppler via source ..."
wget "${POPPLER_SOURCE}"
tar -xvf "poppler-${POPPLER_VERSION}.tar.xz"
cd "poppler-${POPPLER_VERSION}"/
./configure --enable-xpdf-headers --prefix=/usr
make
make install DESTDIR=${INSTALLDIR}
# Ugly hack that also installs into /usr
# so the pdf2html cmake can find and link
# against the libs
make install
echo "Installing fontforge ..."
cd "${HOME_PATH}"
apt-get install -qq -y packaging-dev pkg-config python-dev libpango1.0-dev libglib2.0-dev libxml2-dev giflib-dbg
apt-get install -qq -y libjpeg-dev libtiff-dev uthash-dev libspiro-dev
echo "fetching fontforge via source ..."
wget "${FONTFORGE_SOURCE}"
tar xfz fontforge-20160404.tar.gz
cd fontforge-20160404
./bootstrap
./configure --prefix=/usr
make
make install DESTDIR=${INSTALLDIR}
# Ugly hack that also installs into /usr
# so the pdf2html cmake can find and link
# against the libs
make install
echo "Installing Pdf2htmlEx ..."
cd "${HOME_PATH}"
git clone "${PDF2HTMLEX_SOURCE}"
cd pdf2htmlEX
git checkout v${PDF2HTMLEX_VERSION}
cmake .
make
make install DESTDIR=${INSTALLDIR}
cd "${HOME_PATH}"
# Now package it up!
fpm -s dir -t deb -n pdf2htmlex_poppler_fontforge -v ${PDF2HTMLEX_VERSION} -p ${PDF2HTMLEX_PKG} -C ${INSTALLDIR} usr
cd "${HOME_PATH}"
rm -rf "poppler-${POPPLER_VERSION}.tar.xz"
rm -rf "poppler-${POPPLER_VERSION}"
rm -rf "fontforge*"
rm -rf "pdf2htmlEX"
rm -rf ${INSTALLDIR}
printf "\nYou can find your package at: ${HOME_PATH}/${PDF2HTMLEX_PKG}:\n\n"
ls -l ${HOME_PATH}/${PDF2HTMLEX_PKG}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment