How to convert a printer driver to a stand-alone console application which can generate a printer file containing the bytes to be sent to the printer?

后端 未结 7 641
深忆病人
深忆病人 2020-12-30 05:16

I have a situation where the only way to generate a certain datafile is to print it manually to FILE: under Windows and save it in a file for further processing.

7条回答
  •  不知归路
    2020-12-30 06:09

    At the moment i have one missing link in your explanation, so let me rephrase what i understood:

    • You have a special printer driver on your windows system, that is configured to print into a file.
    • You like to have a simple batch program that can give something to this printer driver to output a binary file.
    • You have a toolchain where this file can be further processed.

    Now my missing part is, what do you want to give to your little batch script, so that it produces your binary file? Do you have a Visio file which should be automatically printed through this driver?

    If yes, you should take a look into this little batch script. It is able to take any file with a registered file extension and send it to the default printer with its default settings. By using these settings you are able to change the printer settings within your windows system from a batch file to make your special driver the default one and putting the output into a file.

    So if i understood you correctly i didn't had the complete solution but i think a good starting point to accomplish your task.

    Update

    Ok, after reading your comment, i fully understood what you like to achieve. To get this to work you have to follow Per Larsens advice to write your own driver with the windows ddk (or to be more precise the Windows Driver Kit [WDK]) and encapsulate the already existing driver.

    So in short and simple: Your driver signs up as new printer driver. When it is called it gets all the raw bytes from the application. Passes it into the driver that can generate your datafile. Get the output from that driver back and do with it whatever you like.

    Some samples to get started can also be found in MSDN as overview or more precisely here.

    But just to say it right beforehand: This is not an easy or simple task and the effort is quite high. Maybe trying to manipulate the driver settings of your special driver through the already given batches or a simple application (written with AutoIt) can also solve your problem, by just interacting (automatically) with the settings of the driver.

提交回复
热议问题