Step 6 - Print a Document

ASP User's Guide > Simple Sample Programs

Sometimes you need to print a generated document on the server, e.g. to generate an invoice. VBScript does not support the Visual Basic printer object or any similiar functionality to select printers, paper bins etc. It is possible, however, to send your document to the default printer. This can be achieved with the following single line of code:

tx.PrintDoc "ASP Document Title", 1, tx.CurrentPages(), 1

The PrintDoc method prints the contents of the Text Control to the system's default printer. The first parameter specifies the document's title in the printer's queue, the following are the first and the last page to print. The last parameter specifies the number of copies. This sample code can be found in the 'step6.asp' sample script.

If you want to print to a file, add a printer driver to your system, which supports the desired output format, e.g. a Postscript driver. Add a new Local Port to your printer configuration and specify a file name for the port, e.g. c:\ The output of this printer driver is redirected to the specified file. The file will be overwritten each time you print to this printer driver.