Solved

Print HTML Page

Posted on 2001-07-17
12
595 Views
Last Modified: 2008-03-17
Hi,
I need to print the HTML page without displaying the print setup dialog?.
I am using the following lines of code to prin the HTML document.
c:\winnt\system32\MSHTML.dll PrintHTML "MyFile.html"
This works fine but it displays the print dialog box. Can any tell me how to avoid the display of this dialog box?

0
Comment
Question by:Thangs
  • 4
  • 2
  • 2
  • +3
12 Comments
 
LVL 2

Expert Comment

by:DirkVe
ID: 6289822
I don't think it's possible to print without that setup dialog.

Please provide some of the code, since I've never used c:\winnt\system32\MSHTML.dll

0
 
LVL 18

Accepted Solution

by:
mgfranz earned 100 total points
ID: 6290639
Printing from script is supported in Internet Explorer 5 and later by calling Window.Print. However, this always displays the Print dialog box, which can't be suppressed. Printing is considered a security issue; a Web page should not have the ability to start a print job without confirmation from the user. Window.Print is not available in Internet Explorer 4.0. To work around this, you can place a WebBrowser control on the Web page and call ExecWB to print, or you can write a custom ActiveX? control that accesses the application's IWebBrowser2 interface and calls ExecWB to print.

http://msdn.microsoft.com/library/en-us/dnie55/html/wb_print.asp?frame=true

But try this;

<HTML>
<HEAD>
<OBJECT ID="wbp"
CLASSID="CLSID:778C58A9-81B6-11D3-BB8F-00C04FA3471C">
</OBJECT>
<SCRIPT LANGUAGE="VBScript">
    Sub Print()
        If Len(wbp.DefaultPrinterName) = 0 Then
            MsgBox "No default printer!"
            Exit Sub
        End If
        wbp.Header = "My Header"
        wbp.Orientation = 2 ' Landscape
        wbp.Print
    End Sub
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" VALUE="Print" ONCLICK="Print()">
</BODY>
</HTML>

0
 
LVL 2

Author Comment

by:Thangs
ID: 6292184
But I am not printing from GUI. My backend class will print the HTML Document. I am developing a C++ application which prints the HTML document.
0
 
LVL 2

Expert Comment

by:DirkVe
ID: 6292582
Since you've posted your question in the Active Server Pages group we all expected that you wanted to print from an asp-application and not from a C++ application.

So try asking the question in that group, I guess you'll reach the right folks. But I still think that you cannot surpress the print dialog since it's standard windows behaviour. What you can try (if your printer is connected to your local pc) is sending the output to lpt, like you do in dos:

dir * >lpt1
or
put the output in a file called doc.txt and use the dos-command:
type doc.txt >lpt1

You probably have some methods in C++ also that can send the output to lpt1 (= default printer port)
0
 
LVL 2

Author Comment

by:Thangs
ID: 6292732
DirkVe,
Since this is related with the HTML pages I asked this Question here. You might have exeperience such a problem.

Since this is not a text file which we can directly direct to the printer using Lpt1 or whatever. This is html page which need formatting before printing.
0
 
LVL 2

Author Comment

by:Thangs
ID: 6292751
mgfranz,
I hope "wbp.DefaultPrinterName" is uspported only in win2k. But I am using windows NT4.0.  Any sugegstions
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 6293423

I wanted to do precisely the same thing only in VB. I am giving you the code below. Because we need to do the formatting, i am using WebBrowser control.

I am sure you will be coding under SOME event, which may not be UI. Constants in code were available while using WebBrowser control. To make sure that the document is completely loaded before printing, I have placed print code in even that fires after loading the document. wbPrintHTML is WebBrowser control.

Private Sub cmdPrintHTML_Click()
    With wbPrintHTML
        .Navigate "File://c:/NitinSontakke/VBProjects/PrintHTML/Contact.htm"
    End With
End Sub

Private Sub wbPrintHTML_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If Len(URL) > 10 Then
        wbPrintHTML.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
    End If
End Sub

Please do let me know if you need any more info.
0
 
LVL 2

Author Comment

by:Thangs
ID: 6293490
NitinSontakke ,
I tried with ExecWB also. This works but it still displays the print dialog.  I understood that OLECMDEXECOPT_DONTPROMPTUSER attribute is disabled in IE 4.0 and above. How do we get around this?

Is it possible to get the lower version of web browser control below version 4.0??
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6293937
I doubt it... it wasn't until IE4 that a print() control was even available, besides why bother... less than 1% of the browser market is usinng a browser below 4.0 standards anyway, and in my opinion, they don't count... ;-)

Did you read the link I posted thangs?
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 6294511
I doubt it too.

I am not entirely sure, about the WebBrowser control version. If the IE version and WebBrowser control version is same, then i am using IE 5.50.4522.1800 and it works
just fine.

0
 
LVL 33

Expert Comment

by:hongjun
ID: 8622904
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[points to mgfranz]

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

hongjun
EE Cleanup Volunteer
0
 

Expert Comment

by:Chmod
ID: 8674348
As recommended

Chmod
Community Support Moderator @Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now