PostScript to PDF

Is there an AppleScriptObjC method for converting a post script file to PDF format?

I have a script that I want to distribute but don’t want the user to have to install anything (like GhostScript or another app) to make it work.

Apple removed the pstopdf shell command.

1 Like

Not that I recall. All the EPS-related stuff is now deprecated, and I’d be surprised if any of it has outlived pstopdf.

1 Like

I wrote an applet that converts PS to PDF using a build of GhostScript included in the resources:

https://mendelson.org/postscripttopdf.html

Feel free to rewrite or reuse anything in this. I don’t know anything about coding, so you can probably make many improvements if you choose to. If so, please let us know.

2 Likes

FYI Here’s the script that generated the EPS file to be converted to PDF. I had given up on that and now just generate plain text. But now I’m going to try with eMendelson’s solution.

use script "filemanagerlib"
use scripting additions

set theCommand to ""

repeat while theCommand is ""
   display dialog "View man page for this command:" default answer theCommand
   set theCommand to text returned of result
end repeat
set errored to false
try
   set manFolderPath to (path to documents folder as Unicode text) & "Unix 'man' Pages (PDFs):"
   set manFile to manFolderPath & theCommand & "-ManPages.txt"
   
   if exists object manFile then
      tell application "Finder"
         reveal item manFile
         try
            open manFile
         on error
            activate
         end try
         return
      end tell
   end if
on error errorMsg number errorNum
   display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
end try
set manFileText to do shell script "man " & quoted form of theCommand & "| col -b -f"

try
   set openFile to open for access file manFile with write permission
on error errMsg number errNum
   close access file manFile
   set openFile to open for access file manFile with write permission
end try
set eof of openFile to 1
write manFileText to openFile
close access openFile

tell application "Finder"
   reveal item manFile
   open item manFile
end tell

@estockly, if your goal is to generate a pdf from shell script files, here is what you can do:

set theMan to text returned of (display dialog "Enter the Shell command name :" default answer "cp" with title "Man page view" with icon 1 giving up after (5 * minutes))
if theMan = "" then return

try
	set theFile to do shell script "man -w " & theMan
on error errText number errNum
	if errNum ≠ -128 then display alert "Applescript sends error number  " & errNum message errText buttons {"Cancel"} cancel button 1
end try

set theTemp to path to temporary items folder
set thePDF to ("" & theTemp & theMan & ".pdf") as «class furl»

do shell script "mandoc -T pdf " & quoted form of theFile & "  > " & quoted form of (POSIX path of thePDF)

tell application "Finder"
	repeat until exists thePDF
		delay 0.1
	end repeat
end tell

tell application "Preview"
	activate
	open thePDF
end tell

Thanks, Jonas, that is exactly what I was trying to do. And now works perfectly, even better than the previous version that used the old shell method.