Developing a Virtual Printer with C#

  • Thread starter Thread starter Przemek M. Zawada
  • Start date Start date
P

Przemek M. Zawada

Dear Ladies & Gentleman!

The base of my point is to create a virtual printer, which invoked by
an window.print() JavaScript command, would parse input from viewed
webpage (composed in XML format - sample 1), and create a
PrintDocument, which will again prompt with PrintDialog for selecting
another printer, which will finally print requested document on real
paper.

Questions:
1. The problem is not with parsing XML document naturally, because
it's pretty easy, but creating, or provoking Windows for creation of a
virtual printer (visible in 'Printer & Faxes'). How it's possible?
2. Is it even possible in C#? In my opinion I need to create some
'driver' for my virtual printer, which would be compatible with
Windows nature, but how shall I start?
3. Where shall I look for any man-help? Does anyone have done it
already?

Sample 1:
<printerData>
<head1> Hello World </head1>
<docBody>
<![CDATA[
My document data here
]]!>
</docBody>
<footer1> My footer text </footer1>
</printerData>

Thank you very much for all help!

All the best,
Przemek M. Zawada
 
Hello Przemek,
Dear Ladies & Gentleman!

The base of my point is to create a virtual printer, which invoked by
an window.print() JavaScript command, would parse input from viewed
webpage (composed in XML format - sample 1), and create a
PrintDocument, which will again prompt with PrintDialog for selecting
another printer, which will finally print requested document on real
paper.

Questions:
1. The problem is not with parsing XML document naturally, because
it's pretty easy, but creating, or provoking Windows for creation of a
virtual printer (visible in 'Printer & Faxes'). How it's possible?
2. Is it even possible in C#? In my opinion I need to create some
'driver' for my virtual printer, which would be compatible with
Windows nature, but how shall I start?
3. Where shall I look for any man-help? Does anyone have done it
already?
Sample 1:
<printerData>
<head1> Hello World </head1>
<docBody>
<![CDATA[
My document data here
]]!>
</docBody>
<footer1> My footer text </footer1>
</printerData>
Thank you very much for all help!

All the best,
Przemek M. Zawada

There's no interface you can implement in C# which is supported by windows
at the moment to write your printer driver against. So you will at least
have to do some (if not a lot) of windows API wrapping. I'd start diggign
in the Windows Driver Development Kit to find the things you have to do.
You can host the CLR in a C++ project and pass all functions to a C# class,
so in theory it should be possible to write a base printer driver wrapper
which wraps all calls to the CLR.

The second problem you'll be facing is that there's no way from a printer
driver to get the contents of the original document. Basically the program
doing the printing will convert the document to a series of GDI/Printer driver
calls to draw the document on the empty pages. So there's no HTML involved
there.

If you want to get to the original sourcem you'll have to write a IE Addin
which will capture the source of the active document and pass it on. This
should also be a simpler route to take. It will however not automatically
capture the window.Priint() javascript command as far as I can tell.

Jesse
 
Hello Przemek,


Dear Ladies & Gentleman!
The base of my point is to create a virtual printer, which invoked by
an window.print() JavaScript command, would parse input from viewed
webpage (composed in XML format - sample 1), and create a
PrintDocument, which will again prompt with PrintDialog for selecting
another printer, which will finally print requested document on real
paper.
Questions:
1. The problem is not with parsing XML document naturally, because
it's pretty easy, but creating, or provoking Windows for creation of a
virtual printer (visible in 'Printer & Faxes'). How it's possible?
2. Is it even possible in C#? In my opinion I need to create some
'driver' for my virtual printer, which would be compatible with
Windows nature, but how shall I start?
3. Where shall I look for any man-help? Does anyone have done it
already?
Sample 1:
<printerData>
<head1> Hello World </head1>
<docBody>
<![CDATA[
My document data here
]]!>
</docBody>
<footer1> My footer text </footer1>
</printerData>
Thank you very much for all help!
All the best,
Przemek M. Zawada

There's no interface you can implement in C# which is supported by windows
at the moment to write your printer driver against. So you will at least
have to do some (if not a lot) of windows API wrapping. I'd start diggign
in the Windows Driver Development Kit to find the things you have to do.
You can host the CLR in a C++ project and pass all functions to a C# class,
so in theory it should be possible to write a base printer driver wrapper
which wraps all calls to the CLR.

The second problem you'll be facing is that there's no way from a printer
driver to get the contents of the original document. Basically the program
doing the printing will convert the document to a series of GDI/Printer driver
calls to draw the document on the empty pages. So there's no HTML involved
there.

If you want to get to the original sourcem you'll have to write a IE Addin
which will capture the source of the active document and pass it on. This
should also be a simpler route to take. It will however not automatically
capture the window.Priint() javascript command as far as I can tell.

Jesse

Thank you Jesse! That'd help me a lot!

All the best,
Przemek M. Zawada
 
Back
Top