Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Swt Print Preview(ole print preview)
Swt Print Preview [message #740431] Tue, 18 October 2011 14:00 Go to next message
rajeev  is currently offline rajeev Friend
Messages: 4
Registered: October 2011
Junior Member
I embed word document in applet using swt. in that all optiuons are working fine other than print preview option. i create a swt button and assign functionality for print preview

olecs.exec(OLE.OLECMDID_PRINTPREVIEW, OLE.OLECMDEXECOPT_PROMPTUSER, null, null);

but it was not excuted and mean while it didnt gave any exception too.please help me out how to do print preview function in word ole
Re: Swt Print Preview [message #741061 is a reply to message #740431] Wed, 19 October 2011 06:32 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
try this
OleAutomation automation = new OleAutomation(clientSite);
        
        // looks up the ID for method Select.
        int[] methodIDs = automation.getIDsOfNames(new String[]{"PrintPreview"});
        int methodID = methodIDs[0];
        
        Variant result = automation.invoke(methodID);
        automation.dispose();


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Swt Print Preview [message #741179 is a reply to message #741061] Wed, 19 October 2011 09:05 Go to previous messageGo to next message
rajeev  is currently offline rajeev Friend
Messages: 4
Registered: October 2011
Junior Member
Hi vijay,

Thanks for your help.I tried out. But its not working. the remaining command & all working except print preview. and it gives exception

Error in script part: unknown protocol: javascript

Any idea?

Advance Thanks.

Rajeev
Re: Swt Print Preview [message #741262 is a reply to message #741179] Wed, 19 October 2011 10:55 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
whats different in your code??

This is working for me..

import java.applet.Applet;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Button;

public class Snippet157 extends Applet {

  org.eclipse.swt.widgets.Display display;

  org.eclipse.swt.widgets.Shell swtParent;

  java.awt.Canvas awtParent;

  public void init() {
    Thread thread = new Thread(new Runnable() {
      public void run() {
        setLayout(new java.awt.GridLayout(1, 1));
        awtParent = new java.awt.Canvas();
        add(awtParent);
        display = new org.eclipse.swt.widgets.Display();
        swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell(display,
            awtParent);
        swtParent.setLayout(new org.eclipse.swt.layout.FillLayout());
        org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame(
            swtParent, org.eclipse.swt.SWT.NONE);
        final org.eclipse.swt.ole.win32.OleClientSite site;
        try {
          site = new org.eclipse.swt.ole.win32.OleClientSite(frame,
              org.eclipse.swt.SWT.NONE, "Word.Document");
          Button b = new Button(swtParent, SWT.PUSH);
          b.setText("Print");
          b.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				OleAutomation automation = new OleAutomation(site);
		          
		          // looks up the ID for method Select.
		          int[] methodIDs = automation.getIDsOfNames(new String[]{"PrintPreview"});
		          int methodID = methodIDs[0];
		          
		          Variant result = automation.invoke(methodID);
		          System.out.println(result != null ? "Successful" : "Failed");
		          System.out.println(result);
		          automation.dispose();	
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
          
        } catch (org.eclipse.swt.SWTException e) {
          String str = "Create OleClientSite Error" + e.toString();
          System.out.println(str);
          return;
        }
        setSize(500, 500);
        validate();
        site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);

        while (swtParent != null && !swtParent.isDisposed()) {
          if (!display.readAndDispatch())
            display.sleep();
        }
      }
    });
    thread.start();
  }

  public void stop() {
    if (display != null && !display.isDisposed()) {
      display.syncExec(new Runnable() {
        public void run() {
          if (swtParent != null && !swtParent.isDisposed())
            swtParent.dispose();
          swtParent = null;
          display.dispose();
          display = null;
        }
      });
      remove(awtParent);
      awtParent = null;
    }
  }
}


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Swt Print Preview [message #742395 is a reply to message #741262] Thu, 20 October 2011 12:59 Go to previous messageGo to next message
rajeev  is currently offline rajeev Friend
Messages: 4
Registered: October 2011
Junior Member
Hi vijay,

i just copy your code and tested but it will give the result as null. whether i need to import any dependency jar other than jface & swt. i just include the screen shot of error msg.

Thanks.
  • Attachment: error.JPG
    (Size: 44.58KB, Downloaded 94 times)
Re: Swt Print Preview [message #742421 is a reply to message #741262] Thu, 20 October 2011 13:27 Go to previous messageGo to next message
rajeev  is currently offline rajeev Friend
Messages: 4
Registered: October 2011
Junior Member
Hi vijay,

Thanks for your help.your code is working fine in MSWord 2007. but the same code not working for MSWord2003. i dont know why its giving null exception.

Anyways once again Thanks for your grat help.

Re: Swt Print Preview [message #742448 is a reply to message #742421] Thu, 20 October 2011 13:57 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Try this snippet and find out the exact function
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/OLEandActiveXexamplesnippet.htm
and then use that function...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Swt Print Preview [message #743033 is a reply to message #742448] Fri, 21 October 2011 04:06 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
By the way ,to avoid all this version problems,u should open your PDF,word etc files in a browser..and from there you could print or print preview them easily.(unless u want word specific handling)

offcoarse there are many preconditions for this to work,but this approach avoids all the version specific handling and then again you already have a precondition of word should be installed on the system..Smile


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Fri, 21 October 2011 05:13]

Report message to a moderator

Previous Topic:Layout composite weird behaviour
Next Topic:Refresh problems with switchable graphics
Goto Forum:
  


Current Time: Fri Dec 19 18:15:21 GMT 2014

Powered by FUDForum. Page generated in 0.02679 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software