Writing text view contents to PDF file

I am using the following code to write the contents of a text view to a PDF file on disk.

script KDSaveViewToPDF
    property parent: class "NSTextView"
    property localNSTextView:missing value
    on saveViewAsPDF_(pdfpath)
        if localNSTextView is not missing value
            set viewBounds to localNSTextView's |bounds|()
            set mydata to localNSTextView's dataWithPDFInsideRect_(viewBounds)
            return mydata's writeToFile_atomically_(pdfpath ,true)
            return localNSTextView
    end saveViewAsPDF_
end script

I am using Xcode 4.6.2 with OSX 10.7.5 and deploying for 10.7.

On my system this works just fine. When I run the application on a Mac server(Mac Pro 2x2.66GHz 6-Core Intel Xeon) (where it has to run) running 10.7.5, then the contents of the PDF are flipped vertically.
Does somebody have a clue why this is happening?