Skip to content

Instantly share code, notes, and snippets.

@DocumentAlchemy
Last active March 15, 2019 09:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DocumentAlchemy/e26b36127896e3dfb2d9 to your computer and use it in GitHub Desktop.
Save DocumentAlchemy/e26b36127896e3dfb2d9 to your computer and use it in GitHub Desktop.
Shell script using https://documentalchemy.com API to convert a PowerPoint file into a PDF.
#!/bin/bash
# powerpoint-to-pdf <PPT-FILE> [<PDF-FILE>]
# Uses <https://documentalchemy.com/> to convert a PowerPoint document to PDF.
# SET YOUR DOCUMENT ALCHEMY API KEY HERE (OR PASS AS AN ENV VAR).
# SIGN UP AT <https://documentalchemy.com/> TO GET YOUR FREE API KEY.
DA_API_KEY=${DA_API_KEY:-"EDs2UQEprGn9aD4vg6HCPhFvgQFDahQgRzzIfocJ"}
# PRINT USAGE MESSAGE
show_help() {
echo ""
echo "Use: powerpoint-to-pdf <PPT-FILE> [<PDF-FILE>]"
echo ""
echo "Set DA_API_KEY to your DocumentAlchemy API key value."
echo "(Currently \"$DA_API_KEY\".)"
echo ""
echo "For example:"
echo " powerpoint-to-pdf.sh myDeck.pptx myDeck.pdf"
echo "or"
echo " DA_API_KEY=myApiKey powerpoint-to-pdf.sh myDeck.pptx myDeck.pdf"
echo ""
}
# SANITY CHECK FOR COMMAND LINE PARAMETERS AND --help.
if [ "$#" -eq "0" ]; then
show_help
exit 1;
elif [[ $1 =~ ^--?(h(elp)?)|\?$ ]]; then
show_help
exit 0;
fi
# PARSE COMMAND LINE ARGUMENTS
SOURCE_FILE=$1
DEST_FILE=${2:-$SOURCE_FILE.pdf}
# EXECUTE REQUEST
if [ -s "$SOURCE_FILE" ]; then
curl -X POST --form "document=@$SOURCE_FILE" -H "Authorization: da.key=$DA_API_KEY" https://documentalchemy.com/api/v1/document/-/rendition/pdf -o "$DEST_FILE"
else
echo "File \"$SOURCE_FILE\" not found."
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment