Examples
|
![]() ![]() ![]() |
![]() |
'Get the text from the TextArea HTML field (named 'TextString') of the posted HTML form
|
TextString = Request.Form("TextString")
|
|
'Get font settings from an HTML INPUT text field (named 'FontSettings')
|
FontSettings = Request.Form("FontSettings")
|
|
'Create the ASP Printer object (ASPPrinterCOM.ASPPrinter) on the web server
|
Set Prn = Server.CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Call the PrintText method to print
|
RetVal = Prn.PrintText(TextString, FontSettings)
|
|
'Clean up
|
Set Prn = Nothing
|
|
![]() |
'In the HTML form, we need to have a hidden field where, upon submitting the form, we store tha entire form code in it. This can be achieved by using the document.all.Form1.outerHTML Java Script or VB Script code
|
|
'Get the entire form contents (all of its HTML code) that were stored in the hidden field 'OrderFormContents'
|
FormContents = Request.Form("OrderFormContents")
|
|
'Append the basic HTML tages (html, head, body, etc.) to the order form HTML code
|
FormContents = "<HTML><HEAD></HEAD><BODY>" & FormContents & "</BODY></HTML>"
|
|
'Create the ASP Printer object (ASPPrinterCOM.ASPPrinter) on the web server
|
Set Prn = Server.CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Send the HTML code to the ASP Printer object
|
RetVal = Prn.PrintHTMLDocFromSource(FormContents)
|
|
'Clean up
|
Set Prn = Nothing
|
|
|
![]() |
'Get the file name from the 'File' field in the HTML form
|
FileName = Request.Form("File1")
|
|
'Get font settings from an HTML INPUT text field (named 'FontSettings')
|
'This is only required for text files. For RTF files, the file will be printed as is with all the layout (colors, margins, images, etc.)
|
FontSettings = Request.Form("FontSettings")
|
|
'Create the ASP Printer object (ASPPrinterCOM.ASPPrinter) on the web server
|
Set Prn = Server.CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'This is for text files
|
'Send the text file to the ASP Printer object
|
'Optionally, we also specify the print margins (left, top, right, bottom respectively)
|
RetVal = Prn.PrintTextFile(FileName, FontSettings, 2000, 1440, 2000, 1440)
|
|
'This is for RTF files
|
'Send the RTF file to the ASP Printer object
|
'Optionally, we also specify the paper orientation, the paper size and the paper bin
|
RetVal = Prn.PrintRTFFile(FileName,,,,, spOrientationLandscape, spPaperA4, spPaperBinLower)
|
|
'Clean up
|
Set Prn = Nothing
|
|
![]() |
'Get the file name from the 'File' field in the HTML form
|
FileName = Request.Form("File1")
|
|
'Create the ASP Printer object (ASPPrinterCOM.ASPPrinter) on the web server
|
Set Prn = Server.CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Send the HTML file to the ASP Printer object
|
RetVal = Prn.PrintHTMLDocument(FileName)
|
|
'Clean up
|
Set Prn = Nothing
|
|
![]() |
'Get the URL address from the HTML form field named 'URL'
|
URL = Request.Form("URL")
|
|
'Create the ASP Printer object (ASPPrinterCOM.ASPPrinter) on the web server
|
Set Prn = Server.CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Send the URL to the ASP Printer object
|
RetVal = Prn.PrintHTMLDocument(URL)
|
|
'Clean up
|
Set Prn = Nothing
|
|
![]() |
'Create the ASP Printer object
|
Set Prn = CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Get the HTML page entire source code
|
HTMLSource = document.documentElement.outerHTML
|
|
'Send the HTML source code to the ASP Printer object
|
'The object will build the HTML document form its source code and will print it
|
RetVal = Prn.PrintHTMLDocFromSource(HTMLSource)
|
|
'Clean up
|
Set Prn = Nothing
|
|
'Notify the user for print completion
|
If RetVal = "" Then
|
MsgBox "Print Completed Successfully!",,"ASP Printer COM"
|
Else
|
'RetVal returns a string containing the error number and error description separated by the pipe (|) character
|
ErrorData = Split(RetVal,"|")
|
MsgBox "Print Error!" & vbCrLf & "Error Number=" & ErrorData(0) & vbCrLf & "Error Description=" & ErrorData(1),,"ASP Printer COM"
|
End If
|
|
|
![]() |
'Create the ASP Printer object
|
Set Prn = CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Get the file name from the HTML field 'File1' (file-type field). This file is located on the client machine
|
FileName = Form1.File1.value
|
|
'Call the PrintHTMLDocument method to print
|
RetVal = Prn.PrintHTMLDocument(FileName)
|
|
'Clean up
|
Set Prn = Nothing
|
|
'Notify the user for print completion
|
If RetVal = "" Then
|
MsgBox "Print Completed Successfully!",,"ASP Printer COM"
|
Else
|
'RetVal returns a string containing the error number and error description separated by the pipe (|) character
|
ErrorData = Split(RetVal,"|")
|
MsgBox "Print Error!" & vbCrLf & "Error Number=" & ErrorData(0) & vbCrLf & "Error Description=" & ErrorData(1),,"ASP Printer COM"
|
End If
|
|
|
![]() |
'Create the ASP Printer object
|
Set Prn = CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Get document parts from the appropriate HTML fields and assign them to the appropriate object properties
|
Prn.DocTitle = document.Form1.Title.value
|
Prn.DocHeader = document.Form1.Header.value
|
Prn.DocFooter = document.Form1.Footer.value
|
Prn.DocText = document.Form1.DocBody.value
|
|
'Get font name and size for each part of the document from the appropriate HTML fields
|
Prn.DocTitleFont = document.Form1.TitleFont.value
|
Prn.DocHeaderFont = document.Form1.HeaderFont.value
|
Prn.DocFooterFont = document.Form1.FooterFont.value
|
Prn.DocTextFont = document.Form1.BodyFont.value
|
|
'Set paper orientation (from the value of the appropriate HTML field)
|
Prn.PaperOrientation = document.Form1.PaperOrientation.value 'spOrientationLandscape = 2, spOrientationPortrait = 1
|
|
'Set line spacing (from the value of the appropriate HTML field)
|
Prn.LineSpacing = document.Form1.BodyLineSpacing.value 'spLineSpacingSingle = 1 (default), spLineSpacingOneHalf = 2, spLineSpacingDouble = 3
|
|
'Send the document to the ASP Printer object.
|
'You can also specify the printer name (as argument), to which the document will be sent
|
RetVal = Prn.PrintDoc
|
|
'Clean up
|
Set Prn = Nothing
|
|
'Notify the user for print completion
|
If RetVal = "" Then
|
MsgBox "Print Completed Successfully!",,"ASP Printer COM"
|
Else
|
'RetVal returns a string containing the error number and error description separated by the pipe (|) character
|
ErrorData = Split(RetVal,"|")
|
MsgBox "Print Error!" & vbCrLf & "Error Number=" & ErrorData(0) & vbCrLf & "Error Description=" & ErrorData(1),,"ASP Printer COM"
|
End If
|
|
![]() |
'Create the ASP Printer object
|
Set Prn = CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Query all physical printer devices attached to the system
|
'This will also retrieve any logical printers (such as FAX printer driver, PDF printer driver, etc.)
|
'The method returns a variant array (string) containing the names of the printers found
|
Printers = Prn.GetPrinters(PrintersCount)
|
|
P = PrintersCount & " printers were detected on your system:" & vbcrlf & vbcrlf
|
|
For i=0 To UBound(Printers)
|
P = P & Printers(i) & vbcrlf
|
Next
|
|
'Clean up
|
Set Prn = Nothing
|
|
'Show the names of detected printers
|
MsgBox P,,"ASP Printer COM"
|
|
|
|
![]() |
'Create the ASP Printer object
|
Set Prn = CreateObject("ASPPrinterCOM.ASPPrinter")
|
|
'Get the file name from the HTML field 'File1' (file-type field). This file is located on the client machine
|
FileName = Form1.File1.value
|
|
'Call the PrintPDFFile method to print
|
RetVal = Prn.PrintPDFFile(FileName)
|
|
'Clean up
|
Set Prn = Nothing
|
|
'Notify the user for print completion
|
If RetVal = "" Then
|
MsgBox "Print Completed Successfully!",,"ASP Printer COM"
|
Else
|
'RetVal returns a string containing the error number and error description separated by the pipe (|) character
|
ErrorData = Split(RetVal,"|")
|
MsgBox "Print Error!" & vbCrLf & "Error Number=" & ErrorData(0) & vbCrLf & "Error Description=" & ErrorData(1),,"ASP Printer COM"
|
End If
|
|
|
|