In fact, it is desirable that each user publish their problematic script, but here everything is described in words.
Well, I’ll start guessing that you already know how to create a text file. Therefore, I will offer a method that uses standard OS X tools, namely the convert-to utility from the LibreOffice.app bundle, to convert a TXT or RTF file to PDF.
Note that it also preserves the RTF markup (great), but I assume there is a better way (with standard OS X like here) that I don’t know of.
.
set txtFile to choose file of type {"rtf", "rtfd", "txt"}
set txtFilePath to quoted form of (POSIX path of txtFile)
set outDirPath to do shell script "dirname " & txtFilePath
do shell script "/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir " & quoted form of outDirPath & space & txtFilePath