Can I use "Save as PDF" in a script and have a $variable as a file name?
yes, it says so right in the dialog box where you specify the path. Just make sure that the variable is a valid path and ends in ".pdf"
Save Records As PDF
Retrieving data ...