Bug 44823 - [browser] print() method for org.eclipse.swt.browser.Browser needed
Summary: [browser] print() method for org.eclipse.swt.browser.Browser needed
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 11 votes (vote)
Target Milestone: ---   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 47937 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-10-14 11:18 EDT by Alexander Ilyin CLA
Modified: 2022-01-12 03:27 EST (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Ilyin CLA 2003-10-14 11:18:38 EDT
I need to print the content of the Browser widget (Send Html page to printer).
So I think it's very useful to supply the method 

public void print() throws PrintException

and more cool method

public void print(PrintData printData) throws PrintException

Where PrintData contains information about how to print (Lanscape or Portrait,
paper size etc). I know this is very difficult (impossible) to realize in case
of MSHTML ActiveX. May be it's can be done with Mozilla-based Html SWT widget?
Comment 1 Christophe Cornu CLA 2003-10-16 15:45:10 EDT
Hi Alexander,

To answer your post from 16/10/2003: adding printing support is not being 
investigated at the moment (see http://dev.eclipse.org/viewcvs/index.cgi/%
7Echeckout%7E/platform-swt-home/faq.html#browserstate). You can vote for this 
PR and if you wish to help, you can also provide printing implementations on 
the platforms supported by the Browser widget.

Chris
Comment 2 Alexander Ilyin CLA 2003-10-17 14:19:52 EDT
Simpliest solution for IE can be to add in Browser.java
I'm not sure it's absolutely correct. This is just idea.
Please check it because I can't compile SWT

public void print() throws BrowserPrintException {
   print(false);
}

public void print(boolean showStdSetupDialog) throws BrowserPrintException {
        checkWidget();

        int[] rgdispid = auto.getIDsOfNames(new String[] { "ExecWB", 
                                             "cmdID","cmdexecopt" }); 
        Variant[] rgvarg = new Variant[2];

        //OLECMDID_PRINT is const from MS headers
        rgvarg[0] = new Variant(OLE.OLECMDID_PRINT); 

        //OLECMDEXECOPT_PROMPTUSER = 1
        //OLECMDEXECOPT_DONTPROMPTUSER = 2
        rgvarg[1] = new Variant(showStdSetupDialog ? 1 : 2); 

        int[] rgdispidNamedArgs = new int[2];
        rgdispidNamedArgs[0] = rgdispid[1];
        rgdispidNamedArgs[1] = rgdispid[2];
        Variant pVarResult =
                auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

      // If prev code is worked then add error handling  
      //  if(pVarResult.getType() == OLE.VT_EMPTY) {
      //      throw new BrowserPrintException(pVarResult.getType());
      //  }
}

Additional info see in help about ExecWB method of the MSHTML


More flexible variant of this function is very difficult to implement with MS
ActiveX because it seems don't support such flaxible tuning before print.
There are ExecWB with 4 arguments may be   pvaIn argument can help????


Comment 3 Miroslav Halas CLA 2004-01-08 09:09:56 EST
As a workaround you can use print() from JavaScript. The problem is that this
doesn't work in SWT Mozilla Widget on Linux with 3.0M6 since the dialog is not
displayed. At least you could fix the problem to display the Mozilla dialogs so
that the javascript woraround can be used.
Comment 4 Alexander Ilyin CLA 2004-01-08 10:33:02 EST
JavaScript is not the workaround because of it don't get me control when and how
to print. How can I access to the JavaScript function from my SWT Java program?

BTW JavaScript + ScriptX seems to be only way programaticaly to control page
parameters: paper size, landscape or portrait etc in the MSHTML ActiveX
Comment 5 Christophe Cornu CLA 2004-03-19 09:26:13 EST
*** Bug 47937 has been marked as a duplicate of this bug. ***
Comment 6 Michal Tkacz CLA 2004-09-23 03:50:18 EDT
It may be obvious, but if you don't want to put javascript print() function
inside the document you're printing, you may just call

browser.setLocation("javascript:print()");

to get the same effect for browsers that support it. This way you may decide
when to print the document.
Comment 7 jxi CLA 2006-11-30 20:42:47 EST
Javascript printing is a workaground, but since the browser keeps poping up the select printer dialog so basically it can't do batch printing. 

We need to do batch printing of many html files. I tried the Java Print API  but there is no service implementation for html. If the SWT browser can provide a print method to bypass the dialog, that would be a very cool feature. Thx
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:16:33 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.