Last active
March 15, 2019 09:08
-
-
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.
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 | |
# 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
See https://documentalchemy.com/demo/powerpoint-to-pdf and https://documentalchemy.com/api-doc#!/DocumentAlchemy/post_document_rendition_format for details.