I think you have to use an editor tool in the background.
I dont have much experience with Apple Script but if you can trigger open a Editor Tool, Put your contents in the editor (while running in background) and then use the print functionality of the editor it will open the print preview and you can trigger the save as pdf option. That might want.

In the code that is provided in the sample, I have not made it scriptable. If you are aware of Swift / Cocoa you might want to make this sample app scriptable as well.