You have to get Ghostscript installed first. Run the script, that's it.
#!/bin/sh
# First, type the ghostscript line, second in GS env quit to generate the pdf
# gs -sOutputFile=Document-unlocked.pdf -sDEVICE=pdfwrite -dNOPAUSE -dbatch -q Document-locked.pdf
# GS>quit()