Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I print?

Posted on 2004-08-30
13
Medium Priority
?
534 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:shaolinfunk
13 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 400 total points
ID: 11939291
0
 
LVL 10

Expert Comment

by:anv
ID: 11940461
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..

0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 400 total points
ID: 11940859
Hi!

 - click Project -> Components, select 'Microsoft Internet Controls'
 - create Webbrowser control and a command button
 - paste this 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_PROMPTUSER, 0, 0
End Sub

Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    Me.Caption = Text
End Sub
'-----------------------------------------------------------------------------------------
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948003
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948126
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948147
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?
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11949713
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11951470
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.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11960826
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.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11960855
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11969179
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985766
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:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_21119659.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.

http://www.experts-exchange.com/Applications/Q_21119831.html

0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11987229
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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question