Link to home
Start Free TrialLog in
Avatar of FadeDude
FadeDude

asked on

Open internet explorer and print web page automatically.

Hi.

I am doing some reports. I generate some HTML code for these reports. I then open Internet Explorer, (shell) with the appropriate html doc (which is my report). Once here, you can go to file, print... it prints. Fine.

I want to automate the printing process, (tell IE to print the doc once opened, open another doc, Print that one, Close, Open another one etc etc.

I.e like a set of 20 different reports generated and printed all without any user intervention.

I am looking forward to your reply.
Thanks
Fade
Avatar of rfgkev
rfgkev

       Dim info As New System.Diagnostics.ProcessStartInfo
        info.FileName = "C:\stuff.htm"
        info.Verb = "print"
        System.Diagnostics.Process.Start(info)

for me this displays the printer select dialog box, and not the actual page. this may be because i've got more than 1 printer on this machine and cant test it otherwise so not sure what happens with only 1 printer.
Avatar of FadeDude

ASKER

Dude, thats very cool, but I need it to print without the user interaction. This app runs on a temrinal server with a lot of printers, so I might have them choose a "desired printer" before the batch printing starts.

Any ideas
Avatar of Éric Moreau
Hi FadeDude,

Do you want to set the printer programmatically? See may article of March 2005 at http://emoreau.s2i.com/

Cheers!
am sure IE always displays the dialog box, so can get printer, no copies etc...

if u had another application that could print html files, you could change the verb to point to that.

The verbs are in Control Panel -> Folder Options -> File Types
Select the file type and click the Advanced button. select the 'Print' verb and click Edit button to see/change what it does
Thanks dude, that will help me a lot, getting and choosing the default printer.

I still (after that), then need to be able to print my html file withou any user interaction.
rfgkev already showed you how to print. If I stand correct, there will be no dialog on the screen.
Quote from rfgkev
"for me this displays the printer select dialog box, and not the actual page"

I will check out the verbs and the rest of the suggestions.
Thanks a lot for all your suggestions. I will hoever only on monday be able to work on this further

Thanks!
I print from Internet Explorer in an old VB6 project that does not require the dialog to pop up.    The solution I used was to:

Add a Reference to the InternetExplorer Object.
Dim _ie as new InternetExplorer

Tell the ie object to navigate to my file
_ie.Navigate "The htmlfile"



Then Add an event handler for _ie_DocumentComplete    This is required to know when the document has finished loading.  If you try to print before it is complete it will not load correctly.

In the DocumentComplete event I call
_ie.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER)

If you want to print more than one document  then within the Document Complete event you can then navigate to your next html document after you call the print.  

Good Luck.
Hi Guys.

jjardine, regarding your suggestion. This does not work out of the box with VB.net.....

I have spend hours on google trying to get info on Automating Internet Explorer....and Nothing.
Am I searching for the from stuff, or is this type of action just very undocumented?

I have no real experience with automation, so I don;t know where to start, and I cant get info on it?

Again, this is basically what I wanne do:

<pseudo code>

make an Internet explorer object
use this object and tell it to .navigate to "file.hmtl"
tell object to print, (landscape, A4)
tell object to navigate to another "file.txt"
Print again
destroy object

</pseudo code>

jjardine's example is basically this, but as I said it doesn't work in vb.net.

I have come up with my own solution to my problem (its not really what I wanted to do, but it will work.

I will put a css-page-break in my html after each report and just do all the reports in one html doc, then print the whole doc.

Any ideas on my above ramble?
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey FadeDude,
  I just uploaded a sample project that prints an html page from ie.  Please take a look at this..  I had to add in the Web Browser control by clicking on the toolbar and selecting add/remove components.  Then under the com tab there is the web browser control.  I dragged the web browser onto the form just to get the correct references then I deleted the browser.   Please let me know if this is helpful to you or not.  Thanks.  

here is the link:   http://www.jardinesoftware.com/codeexamples/IEPrintSample.zip
jjardine, thanks for your effort in this regard.

That should be exactly what I need!