OS 8/9 print-to-PDF without Acrobat

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

Post Reply
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

OS 8/9 print-to-PDF without Acrobat

Post by emendelson »

Here's a way to create PDF files in Mac OS 8.5 through 9.x that doesn't require Adobe's commercial software and doesn't have the limitations of the free PrintToPDF driver which doesn't embed fonts, so most text gets converted to Times New Roman.

In another thread, CharlesS pointed out that the Desktop Printer Utility included the option to hack it in ResEdit so that you could create a desktop printer that sent output to an application to be processed. I've posted a hacked copy of the utility here, together with a sample AppleScript application to show how it's used:

https://www.dropbox.com/s/rzsf50cr1tvbj ... r.sit?dl=1

To create a desktop printer that writes a PDF to the Mac OS desktop (NOT the host desktop, but the desktop in SheepShaver or Qemu) you will need to do the following.

First, download and install MacGhostView32 from Macintosh Garden or elsewhere:

http://macintoshgarden.org/apps/macghostview-32

Next, make sure that Jon's Commands are installed in the Scripting Additions folder. You can find them in many places, e.g.:

http://macgui.com/downloads/?file_id=17717

Next, create an AppleScript application using the following code, which of course can be improved because I'm a total beginner at this kind of thing. The most intelligent part is the "replaceText" routine which I found online.

Code: Select all

-- osax: Jon's Commands

property SS : ":"
property RS : "-"

on open theFile
	
	tell application "Finder" to set deskFolder to the path to the desktop folder
	
	set myDate to day of (current date) as string
	set myMonth to month of (current date) as string
	set myYear to year of (current date) as string
	set myTime to time string of (current date) as string
	set myTimeText to replaceText(myTime, SS, RS)
	set dateNameBase to myDate & "-" & myMonth & "-" & myYear & "-" & myTimeText
	
	set goAhead to false
	repeat while goAhead is false
		
		try
			display dialog "Type a filename for this PDF:" default answer dateNameBase
			set newShortName to text returned of result
		on error
			deleteFile theFile  --Jon's Commands
			error number -128
		end try
		if newShortName is "" then
			deleteFile theFile --Jon's Commands
			error number -128
		end if
		set oldFile to (deskFolder & newShortName) as string
		try
			oldFile as alias
			display dialog "File exists. Overwrite?" buttons {"Yes", "No"} default button 2
			if button returned of result is "Yes" then set goAhead to true
		on error
			set goAhead to true
		end try
		
	end repeat
	
	if length of newShortName is greater than 27 then
		set newShortName to (characters 1 thru 27 of newShortName) as string
	end if
	
	renameFile theFile to newShortName
	
	set newPDF to (deskFolder & newShortName) as string
	moveFile theFile to deskFolder --Jon's Commands
	tell application "macps2pdf"
		open theFile
		delay 1
		set psBusy to true
		repeat while psBusy is true
			set psBusy to fileIsBusy theFile --Jon's Commands
			delay 1
		end repeat
		quit
	end tell
	
	deleteFile theFile --Jon's Commands
	
end open

to replaceText(someText, oldItem, newItem)
	set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
	try
		set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
		set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
	on error errorMessage number errorNumber -- oops
		set AppleScript's text item delimiters to tempTID
		error errorMessage number errorNumber -- pass it on
	end try
	return someText
end replaceText
When you check its syntax, it will as ask you where to find macps2pdf; it's in the MacGhostView32 folder.

Name the script something like WritePDFtoDesktop and save it as an application in a convenient place.

Next, use the hacked Desktop Printer Utility to create a new Desktop Printer, using the option "Process PS File." Set it up to send the output to the AppleScript application that you created above, and give it any name you like.

EDIT: I forgot to mention: When you use this Desktop Printer for the first time, in the Print dialog, make these changes to the default settings: Background Printing, set to Foreground printing (not essential, but faster); Font Settings, check the box "Always download needed fonts"; Save as File, change PostScript level to Level 2 and 3, change Data Format to Binary, and for Font Inclusion, select "All But Standard 13", and click Save Settings.

When you print to this Desktop Printer, after a pause, you'll be prompted for an output filename. You'll be offered a default name based on the current date and time, but you can overwrite it with a better name. Names that are too long will be silently truncated. If the output PDF already exists on your desktop, you'll be prompted to enter another name. If you leave the filename blank, no PDF will be created.

The resulting PDF will be written to your desktop. You'll see the PostScript output file briefly appear on your desktop, but it will be deleted after the PDF gets created.

This is complicated to set up but easy to use in practice. I hope someone finds it useful.

EDIT: The maximum length of the filename is now 27 characters in both lines of code that count characters (I hadn't changed a 31 to 27 when I first posted). EDIT: The colons in the time string needs to be changed to hyphens to avoid truncated filenames.
Last edited by emendelson on Thu Jul 06, 2017 1:16 am, edited 4 times in total.
jrethorst
Tinkerer
Posts: 68
Joined: Sun Nov 05, 2006 1:21 am

Re: OS 8/9 print-to-PDF without Acrobat

Post by jrethorst »

_Very nice_, Ed, as usual. Thank you.

John R.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS 8/9 print-to-PDF without Acrobat

Post by emendelson »

It's too late for me to edit my original post, so here's a slightly revised version of the original code. In the original, if you added ".pdf" to the filename in the dialog box, then the resulting PDF file would get deleted after being made, which is probably not what you wanted:

Code: Select all

-- osax: Jon's Commands

on open theFile
   
   tell application "Finder" to set deskFolder to the path to the desktop folder
   
   set myDate to day of (current date) as string
   set myMonth to month of (current date) as string
   set myYear to year of (current date) as string
   set myTime to time string of (current date) as string
   set myTimeText to replaceText(myTime, ":", "-")   --filenames can't have colons
   set dateNameBase to myDate & "-" & myMonth & "-" & myYear & "-" & myTimeText
   
   set goAhead to false
   repeat while goAhead is false
      
      try
         display dialog "Type a filename for this PDF:" default answer dateNameBase & ."pdf"
         set newShortName to text returned of result
      on error
         deleteFile theFile  --Jon's Commands
         error number -128
      end try
      if newShortName is "" then
         deleteFile theFile --Jon's Commands
         error number -128
      end if
      set oldFile to (deskFolder & newShortName) as string
      try
         oldFile as alias
         display dialog "File exists. Overwrite?" buttons {"Yes", "No"} default button 2
         if button returned of result is "Yes" then set goAhead to true
      on error
         set goAhead to true
      end try
      
   end repeat
   
   --next  three lines addded to original code
   if newShortName ends with ".pdf" then
      set newShortName to (characters 1 thru -5 of newShortName) as string
  end if

   if length of newShortName is greater than 27 then
      set newShortName to (characters 1 thru 27 of newShortName) as string
   end if
   
   renameFile theFile to newShortName
   
   set newPDF to (deskFolder & newShortName) as string
   moveFile theFile to deskFolder --Jon's Commands
   tell application "macps2pdf"
      open theFile
      delay 1
      set psBusy to true
      repeat while psBusy is true
         set psBusy to fileIsBusy theFile --Jon's Commands
         delay 1
      end repeat
      quit
   end tell
   
   deleteFile theFile --Jon's Commands
   
end open

to replaceText(someText, oldItem, newItem)
   set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
   try
      set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
      set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
   on error errorMessage number errorNumber -- oops
      set AppleScript's text item delimiters to tempTID
      error errorMessage number errorNumber -- pass it on
   end try
   return someText
end replaceText
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS 8/9 print-to-PDF without Acrobat

Post by emendelson »

And here's the official download for MacGhostView:

http://www.math.tamu.edu/~tkiffe/tex/pr ... View32.sit
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS 8/9 print-to-PDF without Acrobat

Post by emendelson »

And it turns out that the official download is infected with the (harmless) nVir virus. I've notified the author. Meanwhile, you can get a cleaned copy of the download here:

https://www.dropbox.com/s/3x69uqkpz5qrm ... 2.sit?dl=0
User avatar
adespoton
Forum All-Star
Posts: 4227
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: OS 8/9 print-to-PDF without Acrobat

Post by adespoton »

Here's the proper link for MacGhostView: http://www.kiffe.com/macghostview.html

It's got the 68k, PPC and x86 versions available; I believe all of them are free of nVIR-A.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: OS 8/9 print-to-PDF without Acrobat

Post by emendelson »

adespoton wrote:Here's the proper link for MacGhostView: http://www.kiffe.com/macghostview.html

It's got the 68k, PPC and x86 versions available; I believe all of them are free of nVIR-A.
Those versions are indeed free of nVIR-A because the author now uses the cleaned files that I sent him yesterday as replacements for the infected files that were in the archive until yesterday. Look at the file dates in the archive and you'll see exactly what happened.

EDIT: And I just got a nice note from Tom Kiffe saying that he was now using Disinfectant to remove the virus from all his SheepShaver files.
Post Reply