Link to home
Start Free TrialLog in
Avatar of shaolinfunk
shaolinfunkFlag for United States of America

asked on

How do I print?

I have a form.

There is one control button.

How do I make it so that when I push the button it opens Internet Explorer, goes to www.cnn.com, and prints the webpage automatically?
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium 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
Avatar of anv
anv

add a web browser form to ur project

to it pass the parameter as startingAddress= "www.cnn.com"
in the web browser's documentComplete event

add code to print the page..

ASKER CERTIFIED SOLUTION
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
Avatar of shaolinfunk

ASKER

dbrckovi gave me exactly the solution i was looking for.  
and dhaest pointed me to a really informative website that helped me to understand the webbrowser control.  thank you both.
hey guys,
one other quick question.  how do i bypass that print dialog that pops up?  i want it to automatically print to the default printer.  i don't want to have to click OK on the popup print dialog everytime.  thanks.
actually,
after i click on OK on the print dialog a new "Save PDF as" dialog consequently appears because my default "printer" is really the Adobe option that lets me output any document into .pdf form.  how do i by pass the "Save PDF as " dialog as well?
Hi. Thanks for accepig.

To bypass Printer Dialog just use OLECMDEXECOPT_DONTPROMPTUSER flag. Like this:     ( WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0 )

But I'm not sure you can bypass Adobe's "Save PDF As..." dialog. It is called by the driver itself and Visual Basic has nothing to do with it.
However, maybe you can turn it off in driver settings.

I'm using Adobe Acrobat Distiller for printing to PDF, and in order to disable "Save As" dialog I do the following:

 Control Panel -> Printers -> right click Acrobat Distiller -> Printing Preferences -> Adobe PDF Settings tab -> uncheck Prompt for the PDF Filename

However, I have Adobe PDF Writer installed also, but it doesn't seem to have that option.
To get around the "Save PDF as..." dialog is there a way to write a script/batch file that will type in the name of the file to be saved and then hit the Enter button for me?  

Basically, I am away from the computer when the app is printing the website and I would like to be able to just pick up the printout from the printer.
I'm confused.

Are you printing to a printer or to PDF file?

If you are printing to actual printer then using OLECMDEXECOPT_DONTPROMPTUSER flag, you won't have to press anything becouse printer dialog won't appear at all.

But if you are printing to PDF file, there is one possibility that I can think of at the moment:

 Set everything to run automaticaly.
 - disable printer dialog by using OLECMDEXECOPT_DONTPROMPTUSER
 - disable 'Save As' dialog by unchecking the appropriate checkbox in Acrobat Distiller's settings
 - disable 'confirm Overwrite dialog' also in Distiller's settings
 Basically, set Distiller so it will print allways to the same file without asking to confirm Overwriting.
 In your application, before the page is sent to the printer (Distiller), delete the PDF file if there is one and then send the page to the printer.
 After you send the page to printer, run a routine which will wait for PDF to be created. When Distiller creates the PDF file, rename it or copy it to different location.
Another thing.

Uncheck "View the result in Adobe Acrobat" checkbox also. If you don't, then Acrobat will open and 'lock' the PDF file so you your app won't be able to delete or replace it.
Sorry for the confusion.  I want to print to the PDF file.

(Eventually I want to write a script to print the PDF file at scheduled times using Task Scheduler but that is a whole new question that I will post to this board later on).  

I am using Distiller and your solution works in bypassing the Print dialog.

But then 2 new error dialogs popup when stepping through the following code:

Private Sub Command1_Click()
    WebBrowser1.Navigate "www.cnn.com"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    Me.Caption = Text
End Sub


Error #1: (occurs while highlighting "WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0" in yellow )

Run-time error '-2147221248 (80040100)':
Method 'ExecWB' of object 'IWebBrowser2' failed

I don't know why this error occurs.  After I click on Debug and step through "WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0" the next error occurs.

Error Dialog #2:
"There was an error found when printing the document "res://C:\WINNT\System32\shldoclc.dll/dnserror.htm" to C:\Documents and Settings\All Users\Desktop\*.pdf.  Do you want to retry or cancel the job?  

I am assuming this error occurs because I haven't been given a chance to name the file since it just bypasses the "Save as PDF" dialog?

Thanks for your help.  When we solve this I will add another 100 pts to you.
Hi dbrckovi,

Someone already helped me figure why I kept getting error #1.  Apprently I needed to add WebBrowser1.Stop when the form loads.  If you want to see the solution the URL is here:
https://www.experts-exchange.com/questions/21119659/How-do-I-print.html

However I am still having trouble automating the "Save PDF as" using PDF Distiller or PDF Writer.  I am offering 150 pts for the solution at this URL if you want to continue.  Thanks for your help.

https://www.experts-exchange.com/questions/21119831/150-Easy-Points-Adobe-PDF-Writer-question.html

Hi!

I was off-line for a few days so I wasn't able to respond.
If I figure out something, I'll tell you.