473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Intercept the Print message in C#

I have an application that hosts a web browser control. I would like to
detect when ever the browser tries to print a page and rather than print the
document, store the print job off in a database for printing at a later time.
There are some other controls in my application that the user could print
from, so I can't have this specifically coded to the browser control. It
need to intercept any print message generated from my application. I realize
this will probably take some Interop code. Any hints or suggestions would be
appreciated. Thanks!!
Nov 11 '08 #1
3 5230
There is also the option of creating a print driver of some sort which
will basically act as a virtual printer (something like the PDF print option
that Adobe offers).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael B. Trausch" <mi**@trausch.uswrote in message
news:20081111163230.7dc690f0@zest...
On Tue, 11 Nov 2008 13:02:02 -0800
Bryan <Br***@discussions.microsoft.comwrote:
>>
I have an application that hosts a web browser control. I would like
to detect when ever the browser tries to print a page and rather than
print the document, store the print job off in a database for
printing at a later time. There are some other controls in my
application that the user could print from, so I can't have this
specifically coded to the browser control. It need to intercept any
print message generated from my application. I realize this will
probably take some Interop code. Any hints or suggestions would be
appreciated. Thanks!!

If your application is hosted in a standard Web browser, you will not
be able to intercept the native (browser-provided) print menu item or
icon press. You can have a button in your application that will do
this, but I would advise calling it something other than "print", since
that would cause confusion.

It seems that IE6 supports such a thing, but it's not a
standards-compliant feature (that is, it's a proprietary extension).
Firefox and other standards-compliant browsers don't support such a
hook (and personally, I would disable it if they did, it's a plain
privacy violation; it's nobody's business if I print a page on
Wikipedia or anything else on the Internet).

If having a button or widget in your application doesn't make sense for
what you're doing, I'd consider not using a Web application at all,
instead using a "fat" client to handle whatever client-side work you're
doing. Again, I'd recommend not using "Print" as the toolbar or menu
item because the meaning of such a button is expected to be consistent
with other applications; if you want to direct something to a spool
elsewhere than a print button would traditionally go (to the local
print spool), you should have another name for that command.

--- Mike

--
My sigfile ran away and is on hiatus.
http://www.trausch.us/

Nov 11 '08 #2
All true, but since the OP indicated that the application hosts a web
browser control (the WebBrowser control that I assume), I would assume that
there is ^some^ degree of control of the client execution environment (or
more specifically, that there is an install of some sort where the driver
can be installed, it doesn't have to be set as the default).

Also, since it is a .NET app, this wouldn't be the only cross-platform
concern if the app were ported.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael B. Trausch" <mi**@trausch.uswrote in message
news:20081111164705.6c7b44ce@zest...
On Tue, 11 Nov 2008 16:36:14 -0500
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote:
>>
There is also the option of creating a print driver of some sort
which will basically act as a virtual printer (something like the PDF
print option that Adobe offers).

This assumes total control of the client execution environment, whether
or not the user is doing this is undetectable from the Web application
itself. Also, since it'd be a global setting, may cause far more
trouble than solving the original problem... and, of course, such a
solution is system-dependent. You lose portability if you depend on
being able to deploy something like this across clients, since print
configuration is not inherently cross-platform.

--- Mike

--
My sigfile ran away and is on hiatus.
http://www.trausch.us/

Nov 11 '08 #3
Thanks for all of your replies!.. Yes, my application would have total
control of the WebBrowser control. If the user were to print the current
page, or open a Word document within the control and print it, I would still
like to detect this. I would like them to get the normal PrintDialog, select
their settings and *Print*. I want to capture this print object and stuff it
in the database without actually printing. Is this possible?.. The users
would understand that this is a feature of the application and not a *normal*
printing method.

"Nicholas Paldino [.NET/C# MVP]" wrote:
All true, but since the OP indicated that the application hosts a web
browser control (the WebBrowser control that I assume), I would assume that
there is ^some^ degree of control of the client execution environment (or
more specifically, that there is an install of some sort where the driver
can be installed, it doesn't have to be set as the default).

Also, since it is a .NET app, this wouldn't be the only cross-platform
concern if the app were ported.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael B. Trausch" <mi**@trausch.uswrote in message
news:20081111164705.6c7b44ce@zest...
On Tue, 11 Nov 2008 16:36:14 -0500
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote:
>
There is also the option of creating a print driver of some sort
which will basically act as a virtual printer (something like the PDF
print option that Adobe offers).
This assumes total control of the client execution environment, whether
or not the user is doing this is undetectable from the Web application
itself. Also, since it'd be a global setting, may cause far more
trouble than solving the original problem... and, of course, such a
solution is system-dependent. You lose portability if you depend on
being able to deploy something like this across clients, since print
configuration is not inherently cross-platform.

--- Mike

--
My sigfile ran away and is on hiatus.
http://www.trausch.us/


Nov 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Caleb Hattingh | last post by:
Hi Here is a script I want to be able to write (explanation appears after): *** start of script *** import MyCustomMacroLib # This does the magic I would like help for. # This is not...
13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
0
by: Patricia | last post by:
A legacy application (I don't have the source code for the application) transmits reports to a printer. One of the reports that are sent to the printer needs to be inserted into a database. With...
1
by: zoltix | last post by:
Hi, I am beginner in JavaScript. I would like to intercept all click events on my document. I use this function for that document.onmousedown=click;. It works well. But I would like to...
1
by: Imran | last post by:
Hi, Please bear with me as I have only 1 weeks .NET experience. I am using VB.NET to write a stand-alone client application that connects to a Web service. I successfully send a request for a...
4
by: _max_ | last post by:
HttpWebRequest() allows 'pseudo-browser' simulation to intercept incoming HTML for 'screen scraping', etc. But how would you do the opposite: Programmatically find out what a browser is sending...
2
by: Susan van Houen | last post by:
Hi All, How do I intercept an autopostback on the client side and prevent it from executing the submit? In classic ASP I used to intercept the on_submit and just return false;
1
by: Patriicia | last post by:
A legacy application (I don't have the source code for the application) transmits reports to a printer. One of the reports that are sent to the printer needs to be inserted into a database. With...
7
by: ADN | last post by:
Hi, I am creating a custom HTTPModule to intercept the request of when the user is attempting to retrieve a session variable. For instance, if I set a session variable in my code like so: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.