Without the script that you are trying to convert or some information about your computer and installation, I don't know how helpful I can be. Can you post the script and/or some information about your computer and MATLAB version?
Otherwise, there have been some other questions from users getting Java errors. This thread settled on increasing the Java heap size, so that may be a good strategy for you as well.
You can also use other features to generate a PDF, such as selecting Print and then under Name choose Print to PDF or something similar.
I hope this helps! Good luck!