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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • Last Modified:

Print HTML Page

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
Thangs
Asked:
Thangs
  • 4
  • 2
  • 2
  • +3
1 Solution
 
DirkVeCommented:
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
 
mgfranzCommented:
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
 
ThangsAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DirkVeCommented:
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
 
ThangsAuthor Commented:
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
 
ThangsAuthor Commented:
mgfranz,
I hope "wbp.DefaultPrinterName" is uspported only in win2k. But I am using windows NT4.0.  Any sugegstions
0
 
Nitin SontakkeDeveloperCommented:

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
 
ThangsAuthor Commented:
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
 
mgfranzCommented:
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
 
Nitin SontakkeDeveloperCommented:
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
 
hongjunCommented:
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
 
ChmodCommented:
As recommended

Chmod
Community Support Moderator @Experts Exchange
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now