|
Re: Swt Print Preview [message #741061 is a reply to message #740431] |
Wed, 19 October 2011 06:32 |
Vijay Raj 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 #741262 is a reply to message #741179] |
Wed, 19 October 2011 10:55 |
Vijay Raj 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 #743033 is a reply to message #742448] |
Fri, 21 October 2011 04:06 |
Vijay Raj 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..
---------------------
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
|
|
|
Powered by
FUDForum. Page generated in 0.05051 seconds