PrintRawData Method


Top  Previous  Next


Sends raw data or printer commands to the printer immediately, bypassing any printer drivers.


Syntax

object.PrintRawData(Data, [FileName], [PrinterName], [SetPriorityToFile], [LineFeedsBefore], [LineFeedsAfter], [SendFormFeed], [DocumentName], [OutputFileName], [ErrorNumber], [ErrorDescription])

Where object evaluates to a Raw Data Printer object.


The PrintRawData method has these arguments:


PartDescription  


DataString expression specifying the raw data to print or printer commands to send to the printer.  
 
FileName(Optional). String expression specifying the file name from which the data or printer commands are to be retrieved and sent to the printer. Either Data or FileName (or both) can be specified. May be used with the SetPriorityToFile argument. See remarks below.  
 
PrinterName(Optional). String expression specifying the name of the printer to send the data to.  
 
SetPriorityToFile(Optional). A boolean value specifying whether to print the data specified in the Data argument before printing the file contents or vise versa, in case when both Data and FileName are specified (default is False, i.e. Data will be printed before file contents). See Remarks below.  
 
LineFeedsBefore(Optional). A number (Long) specifying howmany line feeds to send before printing the data, e.g. to advance the printing position on the paper (default is 0).  
 
LineFeedsAfter(Optional). A number (Long) specifying howmany line feeds to send after printing the data (default is 0).  
 
SendFormFeed(Optional). A boolean value specifying whether to send a FormFeed command to the printer after printing the data. If no FormFeed is sent to the printer, data will be printed and the printer head and paper will stop at the last printed character.  
 
DocumentName(Optional). String expression specifying the name of the document that will appear in the printer spooler.  
 
OutputFileName(Optional). String expression specifying the file name where the data will be printed as binary printer data, instead of sending the data to the actual printer. This is equivalent to the "Print to file" option in the Windows Print Dialog.  
 
ErrorNumber(Optional). A variant (Long) that returns the error number when an error occurs while printing the data. See also the Error event.  
 
ErrorDescription(Optional). A variant (String) that returns the error description when an error occurs while printing the data. See also the Error event.  
 




Remarks

This method immediately sends raw data and printer commands (ESC codes, etc.) specified in the Data argument, to the printer. Note that Raw Data Printer does not send its own escape codes to the printer. It just sends whatever data and escape codes you specify in the Data argument, exactly as is, to the printer as raw data.

The following example shows how to use this method to send some raw data (text and commands) to the printer:


   'Declare and create an object instance of Raw Data Printer 
   '(alternatively, you can use the CreateObject method to create an object instance)

   Dim RDP As New RawDataPrinter.Printer

   'Print some raw data string

   RDP.PrintRawData "This raw data is printed by Raw Data Printer!"

   'Send an escape command (set bold printing) with some raw data string (ESC E + text) 
   RDP.PrintRawData Chr(27) & "E" & "This raw data is printed by Raw Data Printer!"

The following example shows how to print raw data on a specific printer:


   'Declare and create an object instance of Raw Data Printer

   Dim RDP As New RawDataPrinter.Printer

   'Print some raw data string to a specific printer and send a FormFeed to eject the paper
   'Note that the printer name must be specified exactly as it is returned by the 
GetPrinters method,
   'which actually is the same name that appears in the Windows Control Panel (Printers and Faxes)

   RDP.PrintRawData "This raw data is printed by Raw Data Printer!", , "EPSON Stylus Photo R200 Series", , True


You can either specify your data in the Data argument of the method, or specify a file name in the FileName argument, that contains the data (and / or commands) to be sent to the printer. You can also specify both Data and FileName and in that case, the contents of the file will be appended to the value in the Data argument and both will be printed. Raw Data Printer will not append any line feeds or carriage returns between Data and file contents, therefore you should append carriage returns and line feeds (vbCrLf), if needed. Also, note that in the case of specifying both Data and FileName arguments, either data will be sent to the printer first and then the file contents are sent, or vice versa, depending on the SetPriorityToFile argument value. For example, if SetPriorityToFile is False (default), Data will be printed first and then the file contents are sent to the printer. If SetPriorityToFile is True, the file contents will be printed first and then Data is printed

The PrintRawData method returns True on success, otherwise False is returned. You can either check the ErrorNumber and ErrorDescription arguments for the error details, or use the Error event to capture errors and check for the error details when an error occurs.

Note: When a printer name is specified in the PrinterName argument, data will be sent to that printer. However, subsequent calls to the PrintRawData method, without specifying a printer name in the PrinterName argument, will send all data to the previously specified printer, unless the object is set to Nothing and a new object instance is created. When called again with another printer name, the data will be sent to the new printer from this point on.