dcsimg

Printing with Word from ASP

By ServerWatch Staff (Send Email)
Posted Jun 14, 1999


This article will give you the basics of how to print to a network printer from Word. by Gary Chalupa gchalupa@inetnebr.com This is the Word version of the Excel printing article. Same concept, almost the same code. Microsoft Word must be installed on the server for any of this to work. Feel free to contact me with questions, comments or just to chat.

If you need to print on a regular basis this method is inefficient. There is a better way documented here.

The code is heavily commented so it should be easy to follow. Once you understand the flow, it is easy to adapt this to other applications as well. There are some preliminary steps you need to take before it will work. I detail these steps below with the code following them.

1. Using Print Manager on the server create a new local port with the name "C:\PCL.out"
Step-by-step:

  • Open My Computer/Printers/File Menu/Server Properties
  • Go to the Ports tab
  • Click "Add Port..."
  • Select "Local Port"
  • Click "New Port..."
  • Enter "C:\PCL.out"
  • Click "OK"
  • Click "Close"
  • Click "OK"
2. Install a printer with a driver that will support ALL of the printers you would like to print to. I recommend the HP Laserjet III. Install this printer as a local printer on the newly created port, and set it to be the default printer.

3. Follow method 2 from Q184291. This will set our printer as the default printer for the system account. A summary of this process is listed here.
Step-by-step:

WARNING: Using Registry Editor incorrectly can cause, system-wide problems that may require you to install Windows to correct them. Neither I, nor Microsoft, guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk.
  • Launch Regedit.exe
  • Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Devices
  • From the Registry Menu, click Export Registry File.
  • Save as Devices.reg
  • Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\PrinterPorts
  • From the Registry Menu, click Export Registry File.
  • Save as PrinterPorts.reg
  • Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Windows
  • From the Registry Menu, click Export Registry File.
  • Save as Windows.reg
  • From the Start Button, select Run. Type "Notepad Devices.reg" and hit enter.
  • Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
  • Save the file and exit.
  • From the Start Button, select Run. Type "Notepad PrinterPorts.reg" and hit enter.
  • Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
  • Save the file and exit.
  • From the Start Button, select Run. Type "Notepad Windows.reg" and hit enter.
  • Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
  • Save the file and exit.
  • From the Start Button, select Run. Type "c:\" and hit enter.
  • Double click Devices.reg
  • Double click PrinterPorts.reg
  • Double click Windows.reg

I used ideas from a couple of different places to put this together and I need to mention them.
Word and ASP
by: Armand Datema

Using ASP and WSH to Print on Your Intranet
by: Jeff Sandquist

Formatted Output using ASP
by: David R. Cline

Q184291 - PRB: COM Objects Fail to Print When Called From ASP
Microsoft Corporation


Download the code here: Wordprint.zip

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date