Last active
January 18, 2019 23:47
Convert pdf to text and compress it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdftotext "somepdffile.pdf" - | apack "somepdffile.xz" - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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