Skip to content

Instantly share code, notes, and snippets.

@u1and0
Last active January 18, 2019 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1and0/ac1d84259a090bfcaa29a0b0f900cf1a to your computer and use it in GitHub Desktop.
Save u1and0/ac1d84259a090bfcaa29a0b0f900cf1a to your computer and use it in GitHub Desktop.
Convert pdf to text and compress it.
pdftotext "somepdffile.pdf" - | apack "somepdffile.xz" -
#!/bin/bash
_pdffetchusage() {
cat << EOF
curl -> pdftotext -> stdout as text
Usage:
pdffetch <options> [url]
Option:
-h | --help: Print this help
pdftotext options: see \`man pdftotext\`
Dependency:
pdftotext
curl
EOF
}
if [ "$1" != '-h' ] || [ "$1" != '--help' ]; then
tmpfile=$(mktemp)
curl -Lo ${tmpfile} "${@:$#}" && pdftotext "${@:1:$#-1}" ${tmpfile} -
# "${@:$#}" : last argument
# "${@:1:$#-1}" : all arguments except last one
trap "rm ${tmpfile}" 0
else
_pdffetchusage
exit 1
fi
#!/bin/sh
_pdftobz2usage() {
cat << EOF
Convert pdffile to text, then compress to bzip2 file.
Usage:
pdftobz2 [pdffilename]
Option:
-h: Print this help
pdftotext options: see \`man pdftotext\`
Dependency:
pdftotext
bzip2
EOF
}
LASTARG="${@:$#}"
if file "${LASTARG}" 2>&1 /dev/null | grep -q 'PDF' ; then # pdf check
BZ2FILE=$(echo $(basename "${LASTARG}" '.pdf').bz2) # rename .pdf to .bz2
pdftotext "$@" - | bzip2 -c > "${BZ2FILE}"
elif [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
_pdftobz2usage
exit 0
else
_pdftobz2usage
exit 1
fi
#!/bin/sh
_pdftogzusage() {
cat << EOF
Convert pdffile to text, then compress to gzip file.
Usage:
pdftogz [pdffilename]
Option:
-h: Print this help
pdftotext options: see \`man pdftotext\`
Dependency:
pdftotext
gzip
EOF
}
LASTARG="${@:$#}"
if file "${LASTARG}" 2>&1 /dev/null | grep -q 'PDF' ; then # pdf check
GZIPFILE=$(echo $(basename "${LASTARG}" '.pdf').gz) # rename .pdf to .gz
pdftotext "$@" - | gzip -c > "${GZIPFILE}"
elif [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
_pdftogzusage
exit 0
else
_pdftogzusage
exit 1
fi
#!/bin/sh
_pdftoxzusage() {
cat << EOF
Convert pdffile to text, then compress to xz file.
Usage:
pdftoxz [pdffilename]
Option:
-h: Print this help
pdftotext options: see \`man pdftotext\`
Dependency:
pdftotext
xz
EOF
}
LASTARG="${@:$#}"
if file "${LASTARG}" 2>&1 /dev/null | grep -q 'PDF' ; then # pdf check
XZFILE=$(echo $(basename "${LASTARG}" '.pdf').xz) # rename .pdf to .xz
pdftotext "$@" - | xz -c > "${XZFILE}"
elif [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
_pdftoxzusage
exit 0
else
_pdftoxzusage
exit 1
fi
#!/bin/sh
_pdftozipusage() {
cat << EOF
Convert pdffile to text, then compress to zip file.
Usage:
pdftozip [pdffilename]
Option:
-h: Print this help
pdftotext options: see \`man pdftotext\`
Dependency:
pdftotext
zip
EOF
}
LASTARG="${@:$#}"
if file "${LASTARG}" 2>&1 /dev/null | grep -q 'PDF' ; then # pdf check
ZIPFILE=$(echo $(basename "${LASTARG}" '.pdf').zip) # rename .pdf to .zip
pdftotext "$@" - | zip "${ZIPFILE}" -
elif [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
_pdftozipusage
exit 0
else
_pdftozipusage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment