Got the script to work eventually for extraction. The next issue is how to extract single pages for multiple pdf files, without it overriding the extractions.
For example,
If we have two PDF files in the source folder, and the javascript executes, it extracts and saves each single pdf file as it should.
The issue lies when it extracts the next PDF file, because it is overriding the extracted single pages which it did for the previous pdf file.