Overview
This component allows you to print from Active
Server Pages. It is useful for kiosks and Intranets which may
require printing at the server. With aspPrint you can print
something other than the current web page contents. You can
print fields from a database query, a log file, or any other
text programmatically. Please note that aspPrint does not give
you control over what is printed at a client machine, only at
the server.
Properties
And Methods
aspPrint has
grown very complex and now exposes quite a few properties and methods. You can set the font,
the font size, the font color, the page orientation and font effects like
bold, italic, or underlined text. There are also
special functions for drawing tables, printing a subset of
HTML tags, and printing images. This version of aspPrint uses completely
different code than the previous version so if you are using
the limited aspPrint, you should closely follow the
installation directions in the help file to avoid version
conflicts. This new version of aspPrint is even better for use
in Windows Script Host because it offers better printing
options than you get by sending output to lpt1:.
New Image File Printing Capabilities!
aspPrint can
finally print JPGs, GIFs, and BMP image files. Just supply
the file path to the image file and the X and Y coordinates.
NOTE: On a web server, this must be the physical file path and
not a relative url.
Recent Changes
07/12/2004
Added code to printImage method to
set the image dimensions for the print out. This allows you to
print large images in reduced sizes.
05/23/2004
Added code to printImage method to
set various Printer properties. This allows you to print just
an image without any text.
11/08/2003
Changed the
CurrentX and CurrentY data types from Integer to Long because
printing exceptionally long strings can exceed the maximum
value for the Integer data type.
XBM Image File Capabilities
aspPrint can print graphics using the XBM image file format. XBM files are
ideal for use with aspPrint because the information needed to
create the image can be sent to the component as a text string,
eliminating the need to load a file.
HTML Parsing
Capabilities
aspPrint now
supports some limited ability to parse HTML code and format text
according to the HTML tags found. This also gives you the
ability to change text formatting within a line or document. See
the updated help file for some important limitations to HTML
parsing. This new feature uses regular
expressions which means your VBScript engine must be
updated to version 5.5!
NT Server / Windows
2000 Server Problem
My server testing has revealed a
problem which requires some sophisticated server configuration
to solve. You can find complete details on the problem and its
solution by reading Microsoft Knowledge Base Article Q184291.
However, a better solution to this problem is to create a Microsoft Transaction
Server package for aspPrint on Windows NT or a COM+ Application
on Windows 2000 (see revised help file). aspPrint usually works
when created in a Windows Script Host test script.
ASP.NET and aspPrint
You probably will not need aspPrint to
add printing capabilities to your web applications written for
ASP.NET. The .NET Framework class library for printing can be
used in your code-behind file. I have experimented with a simple
example that prints out a text file without opening up a printer
dialog box. See source code.
You can also use aspPrint in ASP.NET by creating a Runtime
Callable Wrapper for the COM component.
Read Instructions
New Example Script
<%
Set objPrint = Server.CreateObject("aspPrint.ServerPrint")
objPrint.setPrinter = "HP DeskJet 600 (Color)"
objPrint.setPaperSize = 1
objPrint.setOrientation = 1
objPrint.setColorMode = 2
' the following four properties are optional
objPrint.setPrintQuality = -2
objPrint.setDuplex = 1
objPrint.setCopies = 1
objPrint.setPaperBin = 4
' You must now call setDocument after setting all the document properties
objPrint.setDocument
objPrint.setForeColor = vbRed
objPrint.setFont = "Times New Roman"
objPrint.setFontSize = 20
objPrint.setFontBold = False
objPrint.setFontItalic = True
objPrint.setFontUnderline = False
' 1440 twips to an inch
objPrint.setCurrentX = 1440
objPrint.setCurrentY = 1440
' centerText has been changed to a property to fix a bug
objPrint.centerText = False
objPrint.doPrint("Hello World")
' building a xbm image file string
' Note that the first three lines must have a carriage return and line feed
strXBM = "#define trash_width 16" & vbCrLf
strXBM = strXBM & "#define trash_height 16" & vbCrLf
strXBM = strXBM & "static char trash_bits[] = {" & vbCrLf
strXBM = strXBM & "0x00, 0x01, 0xe0, 0x0f, 0x10, 0x10, 0xf8, " & _
"0x3f, 0x10, 0x10, 0x50, 0x15," & vbCrLf
strXBM = strXBM & "0x50, 0x15, 0x50, 0x15, 0x50, 0x15, 0x50, " & _
"0x15, 0x50, 0x15, 0x50, 0x15," & vbCrLf
strXBM = strXBM & "0x50, 0x15, 0x10, 0x10, 0xe0, 0x0f, 0x00, 0x00};" & vbCrLf
objPrint.printXBM(strXBM)
objPrint.printImage CStr("C:\test.bmp"),CInt(1500),CInt(500)
' or specify the image dimensions using the optional width, height arguments
objPrint.printImage CStr("C:\test.bmp"),CInt(1500),CInt(500),4000,4000
' You must call endDocument when you are ready to print
objPrint.endDocument
%>
drawTable Method Example Script
<%
Set objP = Server.CreateObject("aspPrint.ServerPrint")
' Only set these properties before calling the drawTable method
objP.setFont = "Times New Roman"
objP.setFontSize = 20
objP.setFontBold = False
objP.setFontItalic = True
objP.setFontUnderline = False
' Note that you don't use parentheses
objP.drawTable 2,2,"Expense,Cost,Date","Supplies,$50.00,Groceries,$15.00"
' You must call endDocument when you are ready to print
objPrint.endDocument
%>
printHTML Method Example Script
<%
Set objP = Server.CreateObject("aspPrint.ServerPrint")
' You must set these properties
objP.setColorMode = 1
objP.setPaperSize = 1
objP.setOrientation = 1
' Note that the italics tag within the font tag had to be lowercase
' Note that the bold and underline tags had to be uppercase
' Note that the italics tag had to enclose the entire string within the font tag
' Note that the break tag was not within another tag block
' Note the use of two double quotes around the face and size attributes
strHTML = "The <B>bold</B> word will be <U>underlined</U><BR> _
<font face=""Courier"" size=""5""><i>New line in Courier, size 5, _
and italics.</i></font>"
objP.printHTML(strHTML)
' You must call endDocument when you are ready to print
objPrint.endDocument
%>
Pricing & Payment
Options
Because aspPrint is a simple server component with
few features I will offer the aspPrint.dll as an email
attachment for a mere $10.00 fee.
I originally wrote this component for a kiosk project. I only
found one commercial component available for printing at the
server and it was very expensive. You can pay for aspPrint by
sending money to my PayPal account using my email address: robert_robbins@verizon.net

Demo
Download & Help File
A demo version is available for you to
download.
It appends a copyright statement at the end of every printout.
Examples Download
A few example scripts and utilities are available
as a separate download.
Using Word To Print
You could use a
Windows Script Host VBScript batch file to create an instance of
Word and utilize its printing capabilities but this method can
leave many Word processes running and it quickly degrades the
server's performance. The WScript.Sleep line gives Word enough time
to print and then destroys the process. This solution does allow
you to use Word's ability to render HTML.
Dim wApp
Set wApp = WScript.CreateObject("Word.Application")
wApp.Documents.Add
wApp.Documents.Open("C:\WEBSHARE\WWWROOT\DHTML\webpage.html")
wApp.Documents(1).PrintOut
wApp.Documents(1).Close
WScript.Sleep 10000
wApp.Quit
Set wApp = Nothing
Using LPT1 To Print
' Chr(12) is a Form Feed
strText = "Print using plain text" & Chr(12)
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile("LPT1:", True)
f.Write(strText)
f.Close
Set fs = Nothing
Set f = Nothing
Frequently Asked Questions
Question:
Does aspPrint support network printers?
Answer:
Network printers are not supported if the printer name appears as a Universal Naming Convention path (UNC) on the Printer Test Page (i.e. \\computer_name\printer_share_name). However, if the printer has a regular printer name and you print to the UNC as the port, then aspPrint will be able to print to that printer.
Complete Instructions
Question: How do I control the
page breaks for a web page printout?
Answer: You can specify page
breaks, text color, and the background color using style
sheets.
<STYLE TYPE="text/css">
#break
{
PAGE-BREAK-AFTER: always;
}
</STYLE>
<P ID="break">The text for this page</P>
The page break will come after the closing </P> so text
after that appears on a new page of the printout.
<STYLE MEDIA="print">
BODY
{
background-color : #FFFFFF;}
FONT
{
color : #000000;
}
</STYLE>
Only works in Internet Explorer 4.0 or
above.