Login  •  Register


The time is now: Sun Sep 24, 2017 7:30 pm

Emaculation wiki  •  Delete all board cookies



Post new topic  Reply to topic Page 1 of 1 [ 4 posts ]
Print view Previous topic  |  Next topic
Author Message
PostPosted: Wed Jul 05, 2017 12:41 pm 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 725
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:
-- 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.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Wed Jul 05, 2017 6:50 pm 
Offline
Tinkerer

Joined: Sun Nov 05, 2006 1:21 am
Posts: 59
_Very nice_, Ed, as usual. Thank you.

John R.


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Fri Jul 07, 2017 12:14 pm 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 725
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:
-- 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


Top
 Profile  
Reply with quote Post a reply  
PostPosted: Sun Jul 09, 2017 4:52 pm 
Offline
Forum All-Star

Joined: Tue Oct 14, 2008 12:12 am
Posts: 725
And here's the official download for MacGhostView:

http://www.math.tamu.edu/~tkiffe/tex/pr ... View32.sit


Top
 Profile  
Reply with quote Post a reply  
Display posts from previous:  Sort by  
Post new topic  Reply to topic Page 1 of 1 [ 4 posts ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
 

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group