Tuesday, November 20, 2012

Creating a Free PDF Printer in Windows 7 using Ghostscript and Redmon that is one tenth the size of a full Adobe install

(download a pdf of this article with screenshots here)

Adobe PDF's are the lingua franca of online document distribution and while the Adobe Acrobat Professional software is great, it is rather expensive for students, teachers, or anyone who wants to save $115-$180.  The steps described below will give you a completely free working PDF printer but it is important to point out that this won't let you create forms, binders, or any of the advanced Acrobat features that come in the commercial package.  It will however let you render documents to a PDF exactly like you would see on your printer and that is 80-90% of what most people need.

In addition, the total install will only occupy ~40MB on your computer, which is approximately one tenth the size of the smallest Acrobat Professional install (and it doesn't require a reboot).

At a very high level we are going to do 3 things:
  1. Create a virtual printer port that works just like a USB cable or network address does for a real printer using a free program called RedMon.
  2. Attach a printer driver (that comes with Windows) to that port which creates PostScript output (PostScript is a page description language that tells printers what to print) 
  3. Pipe the PostScript output to a free, open source, rendering engine called "Ghostscript" that will turn it in to a PDF (or TIFF, or PNG... it can do lots of neat things)
That's it.  Here are the step by step instructions for creating a pdf printer in Windows 7

Step 1: Installing a virtual Printer Port using RedMon

  1. Download RedMon, the Redirection Port Monitor.  The latest (as of this writing) download is version 1.9 and can be found here.  The RedMon home page is found here.
  2. Unzip Redmon19.zip and run the appropriate 32 (setup.exe) or 64 bit (setup64.exe) installer.  You may need to be an administrator on your machine to do this so either log in as an admin, or right click on the appropriate setup executable and choose "Run As Administrator"
  3. Click "Yes" to the dialog asking "Do you want to install the RedMon redirection port monitor?"
  4. Click "OK" on the "Installation Successful" dialog.
  5. Don't worry that there aren't any icons or apparent signs of something being installed, You have actually added a new type of port called a "Redirect Port" to the guts of Windows.

Step 2: Create the Virtual PDF Printer using a Windows Driver

  1. Open "Devices and Printers from the "Start" menu
  2. Click "Add a Printer" in the upper left
  3. Choose "Create a new port:" and select "Redirected Port"
  4. Use the Port Name "RPT1:" (this should be the default) and click "OK"
  5. Now choose a printer driver from the list (Note: The printer MUST be postscript.  An "HP ColorLaserJet 2800 PS" works because it is both color and postscript).
  6. Name the printer something useful (like "PDF Printer" for example)
  7. Decide whether or not to share the printer... it is easiest to choose "Do not share this printer"
  8. Windows should install the printer driver.  You will have a new printer in your "Devices and Printers" window
  9. Click "Finish"  Don't click "print a test page" because nothing will happen yet, you need to redirect the PostScript to your rendering engine using the steps below.

Step 3: Install a PostScript rendering engine using Ghostscript

  1. Download Ghostscript.  The latest version (as of this writing) is found here.  You will need to select the correct 32 or 64 bit version depending on your version of Windows.  The homepage for Ghostscript is here.
  2. I find it is easier to create a folder called "gs" before I install Ghostscript.  I do this at the root of my system drive: "c:\gs"  This removes the spaces from the folder names and just makes Ghostscript behave better.
  3. Run the Ghostscript installer downloaded from step 1. (Click "Next")
  4. Agree to the license terms after carefully reviewing them.
  5. Choose the installation folder "c:\gs"
  6. Let the install finish.
  7. Now open notepad.exe and add the following text to it:

    #begin config file c:\gs\pdfwrite.txt
    #creates a 600dpi, letter sized PDF
    #end config file c:\gs\pdfwrite.txt
  8. Save this file with the filename: c:\gs\pdfwrite.txt  This configuration file will be used to tell Ghostscript how to create a PDF file.  This will create a 600 dpi Letter sized PDF from your printed output.
  9. Optional:  You can actually create many printers and do things like create TIFF images using different config files and printer names.  Here is a file named "c:\gs\tiffwrite.txt" that creates TIFF images.  If you created another virtual port (RPT2:) and used this file instead in the above instructions, you would be making TIFF's instead of PDF's

    #begin config file c:\gs\tiffwrite.txt
    #creates a 600 dpi Black and White Group 4 TIFF
        #sDEVICE info from http://pages.cs.wisc.edu/~ghost/doc/cvs/Devices.htm
    #end config file c:\gs\tiffwrite.txt

Step 4: Configure your Virtual PDF printer to use Ghostscript

  1. Go to "Devices and Printers" from the "Start Menu"
  2. Double click on the printer created above "PDF Printer"
  3. Double click on "Customize your printer"
  4. Select the "Ports" tab and click "Configure Port" for "RPT1:"
  5. Browse to "c:\gs\bin" and select gswin64c.exe.  Your "Redirect this port to the program:" field should read "c:\gs\gs\bin\gswin64c.exe"
  6. The "Arguments for this program are:" Field should be the following text exactly:

          @C:\gs\pdfwrite.txt -sOutputFile="%1.pdf" -c .setpdfwrite -f -
  7. Select "Prompt for filename" under "Output"
  8. Select "Hidden" under run
  9. Click "OK"
  10. Select the "Advanced" tab and choose "Print directly to the printer
  11. Under the “Device Settings” tab we will make 2 changes.  The first is to set “Send Ctrl-D before each job” to “No.” And then set the “Wait Timeout” to 1 second (this is a very fast printer since it isn’t actually printing anything).  Finally Click “Apply” to commit the changes
  12. Print a test page, you will be prompted for a file name and directory to save your pdf in.
  13. Open your freshly minted PDF in any reader of your choice (At a tiny 4.2 MB, my favorite is Sumatra PDF Reader)
That is it.  You should be able to create PDF's at will by using this simple set up.  To do this, simply print a document like you would any other document, but instead of choosing a physical printer, choose the "PDF Printer"


Farah El uasghiri said...

when I try to apply the modification on redirect port, it doesn't work,
it throws me this exception
"une erreur s'est produite lors de la configuration de port. Impossible de terminer cette operation'erreur 0*00001) "
what I must to do?

Juan Vico said...

Very interesting article. I thought the whole point of using ghostscript is to turn a non postscript printer into a ps printer. Will this work also with laserjet printer?

Juan Vico said...

Very interesting and helpful post.
I us ghostscript to print postscript color separations with a non postscritpt printer, using the gs view software and it works fine.

If the printer is redirected using redmon as you described,could it print directly from illustrator (bypassing the need to save the file as a*.ps file)?


Anonymous said...

Michael, I almost do everything but at the end I cannot print a pdf file. Also, I did not find the font folder on gs.

ChrisV said...

I followed your instructions but I am having zero success printing a test page.