Virtual printing technology research report
Total
1.1 What is virtual printing?
What is virtual printing? Simply, virtual printing is virtual out of the operating system, and this virtual printer can print all printable documents into BMP images. The format of the document can usually be a variety of various, general Office series, and other files, as long as it can be printed on the actual printer, it can be used.
1.2 What are the benefits of virtual printing?
So what is the benefit of virtual printing? Virtual printing has a wide role in collaborative work. For example, you can print a Word document as a BMP image, and then send it to others, and others can browse, even modify the file even if there is no corresponding reading software installed. In this case, it solves the compatibility problem due to the difference between the system installation software.
2 principle
The main ideas are as follows:
1. First of all, of course, it is necessary to virtual out in the system, and set our printers to the default when printing the document, the data stream of the document to be printed can be intercepted by us. For this purpose, if you install the printer, the Windows system has its own API function, but we need to provide the printer's driver, this is the most critical.
2. For the printer's driver, from the description of the reference DDK, Microsoft provides a universal printer driver, this driver is a standard printer driver of Microsoft's design. In this case, the driver's problem is also solved, and the printer can be installed. However, because the driver is used, the data stream of the document cannot be obtained.
3. Fortunately, the universal driver of Microsoft above is not completely dying, allowing users to make a plugin in accordance with certain interface criteria to perform interactions with the driver. Even the data stream can be obtained, so that we can complete the data into our own BMP file.
4. Through the above analysis, the entire idea is completely clear. Through further analysis of DDK, we get some information:
Printing processes using universal prints can be summarized as follows:
As can be seen from the above, Microsoft's general-purpose print drive mainly contains two large components, one of which is unidrvui.dll, which is responsible for providing some of the user interface to allow users to set some properties of printing. The other is unidrv.dll, which is responsible for obtaining the data stream from the Windows graphics generator, and then transfer to the printer. In addition, we can see two optional plugins, one is user interface plug-in, primarily based on user interfaces for property pages and tree controls, can change some of the printer, mainly interact with Unidrvui.dll. The other is RENDING PLUG-IN, a separate implementation plug-in with GDI graphics generator, converts the call to GDI to the printer command, which is mainly interacting with unidrvui.dll. This is a very clear thing. Our main task is to achieve a rendering plug-in's plugin, then use this plugin to get the graphics data stream, and finally saved to the file.
3 implementation
1. For installing printers, Windows has a set of APIs to install directly:
l GetPrInterdriverDirectory's catalog of printer drivers and copy the drivers to be here.
l AddprinterDriver first install the printer driver program
l Addprinter Install the printer, use the above-installed driver
l SetDefaultprinter settings become default printers
l DeletePrinter When uninstalling the printer
2. For the plugin to write the rending plug-in, there is a ready-made example in DDK, but this example is just a framework, what is not done. In this case, we need to transform this example so that she first gets the data stream from the driver, and then saves the data stream into a standard BMP file.
l First, we must interact with the driver. In this way, we must expose the interface, then the driver will stream the data into our plugin. Here we only have to expose the imageProcessing interface, which tells the driver, I need further processing of the image, please transfer the image data to me. In this case, the drive is called to call this function and pass the image data data over.
l Then there is a need to introduce the printed process. Generally, Unidrv, drivers using GDI management surfaces generally have such a process process:
EnableDriver ----- init undrv driverenablepdepdev ----- init pdev structurestartdocstartpageif (Use Banding) // The driver is used to dynamically determine, depending on the size of the amount of data {StartBandingWhile (Not at the end of page) { Drawing (PRE-Process, Callback to Unixxxx, Post-Process) NEXTBANDIF (UserProcess) // If this interface exists {imageProcess --- can get BMP data here
}}} else {Drawing (BLT, PROCESS, CALLBACK TO UNIXXXXX, POST-Process) Sendpageif (Use ImageProcess) // If this interface exists {imageProcess}} EnddocdisablePdevdisableDriver
3. If so, we have obtained image data, and finally we can save them into files. Here we write on every scan line, and finally add a bitmap file header. All the processes of printed have been completed.
4 existence problem
There is still future issues to improve:
l At present, only the default A4 paper size is supported, and the image size of the printed image is 2338 * 1654, and it is hoped to support more formats.
l Do not test all printable documents, there may be problems with possible individual documents.
l At present, only BMP formats are only supported, followed by support JPG and other formats.
--- End of file -----