Skip to content

Instantly share code, notes, and snippets.

@avandeursen
Forked from jacobsalmela/convertDOCXtoPDF.sh
Created January 4, 2017 14:55
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 avandeursen/3b952feafd42be175193c8df36b0e50c to your computer and use it in GitHub Desktop.
Save avandeursen/3b952feafd42be175193c8df36b0e50c to your computer and use it in GitHub Desktop.
Converts a DOC or DOCX to a PDF with a right-click
#!/bin/bash
# Jacob Salmela
# 2016-03-12
# Convert annoying DOCX into PDFs with a right-click
# Run this as an Automator Service
###### SCRIPT #######
for f in "$@"
do
# Get the full file PATH without the extension
filepathWithoutExtension="${f%.*}"
# Convert the DOCX to HTML, which cupsfilter knows how to turn into a PDF
textutil -convert html -output "$filepathWithoutExtension.html" "$f"
# Convert the file into a PDF
cupsfilter "$filepathWithoutExtension.html" > "$filepathWithoutExtension.pdf"
# Remove the original file and the temporary HTML file, leaving only the PDF
rm "$f" "$filepathWithoutExtension.html" >/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment