Not being able to find easy to use tools to extract the javascript code contained in a pdf file in plaintext, nor tools to update the javascript in a pdf without changing anything else. I wrote those two small command line java tools using the excellent iText library.
PDF2JS will extract the javascript from the pdf passed as argument. On windows an example way to use it is: “java -jar pdf2js.jar myinput.pdf”, and it will output the javascript in myinput.pdf.ps.
JS2PDF will replace the javascript in the input pdf file, and write the result into the output pdf file. On windows and example way to use it is: “java -jar js2pdf.jar original.pdf javascript.js output.pdf”, the file output.pdf will contain the updated javascript.
For those interested the very simple code for each tool is provided within the archives.
Also if the pdf file you are working with has usage restrictions, make sure you remove them using the excellent qpdf with the following command line: qpdf –decrypt protected.pdf output_unprotected.pdf