| Article ID | : | 322090 |
| Last Review | : | May 4, 2006 |
| Revision | : | 7.1 |
This article was previously published under Q322090
SUMMARY
This step-by-step article shows you how to use Win32 spooler functions from a program that you create by using Visual Basic .NET.
You may have to send raw data to a printer to do the following:
To send these types and other types of raw data to a printer, your code must work with Win32 Spooler Application Programmer Interfaces (APIs). The following code shows how to read the contents of a preformatted file into memory, and then send those bytes to the printer by using WritePrinter.
NOTE: You cannot use this approach in the same print job as a native PrintDocument print job. You must either use the .NET Framework to print or send your own print job bytes.
More information
To send raw data to a printer from the Microsoft .NET Framework, your program must work with Win32 spooler functions. Through the .NET Framework, you can print by using PrintDocument, PrintController, and associated classes. However, with the .NET Framework, you cannot send preformatted printer-ready data to a printer.You may have to send raw data to a printer to do the following:
| • | Send escape sequences. |
| • | Download, and then use soft fonts. |
| • | Spool preprinted files. |
NOTE: You cannot use this approach in the same print job as a native PrintDocument print job. You must either use the .NET Framework to print or send your own print job bytes.
Create a project that prints preformatted data
To create the project, follow these steps:| 1. | Start Visual Studio .NET. On the File menu, click New, and then click Project. Under Project Types, click the Visual Basic Projects folder. On the Templates list, click Windows Application, and then click OK. By default, Form1 is created. |
| 2. | On the View menu, click Toolbox to display the Toolbox, and then add a button to Form1. This button is named Button1. |
| 3. | Add another button to Form1. This button is named Button2. |
| 4. | Double-click Button1. The code window for the form appears. |
| 5. | Replace the Button1_Click subroutine with the following code:
|
| 6. | Replace the Button2_Click subroutine with the following code:
|
| 7. | Insert the following code at the top of the file:
|
| 8. | Add the following code inside the main application namespace but outside any class definitions:
|
| 9. | Press F5 to build, and then run the program. |
| 10. | Click Button1 to load and print a file's contents. |
| 11. | Click Button2 to print a string. (You may have to eject the page manually because the string is sent without the formfeed command.) |
REFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
138594 (http://support.microsoft.com/kb/138594/) How to send raw data to a printer by using the Win32 API



浙公网安备 33010602011771号