Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] SWT and acrobat activex control

I am trying to get the Acrobat Active X control working in SWT. I was wondering if anyone has done this? I have pasted the code I have so far below. The shell window appears but there is no control visible. I have tried both OleClientsite and OleControlSite.
---------------------------
t0md
 
public static void main(String[] args)
{
 Display display=new Display();
 Shell shell=new Shell(display);
 GridData data = "" GridData(0);
 shell.setLayoutData(data);
 shell.setLayout(new org.eclipse.swt.layout.FillLayout());
 
 ViewForm pdfForm=new ViewForm(shell,SWT.NONE);
 OleFrame PDFFrame=new OleFrame(pdfForm,SWT.NONE);
 
 // Border on right-hand side to make separation more obvious
 pdfForm.setBorderVisible(true);
 
 GridData gridData=new GridData(GridData.FILL_HORIZONTAL|GridData.FILL_VERTICAL);
 gridData.horizontalSpan=10;
 PDFFrame.setLayoutData(gridData);
 PDFFrame.setSize(300,200);
 
 try {
  // Create an Automation object for access to extended capabilities
//  OleControlSite PDFControlSite=new OleControlSite(PDFFrame,SWT.NONE,"PDF.PdfCtrl.1");
  try {
   OleClientSite PDFClientSite=new OleClientSite(PDFFrame,SWT.NONE,"PDF.PdfCtrl.1");
 
//   OleAutomation oleAutomation=new OleAutomation(PDFControlSite);
   OleAutomation oleAutomation=new OleAutomation(PDFClientSite);
 
//   int result = PDFControlSite.queryStatus(OLE.OLECMDID_PRINT);
   int result = PDFClientSite.queryStatus(OLE.OLECMDID_PRINT);
   if ((result & OLE.OLECMDF_SUPPORTED) == OLE.OLECMDF_SUPPORTED)
    System.out.println("OLE.OLECMDID_PRINT is supported");
   else
    System.out.println("OLE.OLECMDID_PRINT is NOT supported");
   if ((result & OLE.OLECMDF_ENABLED) == OLE.OLECMDF_ENABLED)
    System.out.println("OLE.OLECMDID_PRINT is enabled");
   else
    System.out.println("OLE.OLECMDID_PRINT is NOT enabled");
 
//   result = PDFControlSite.queryStatus(OLE.OLECMDID_OPEN);
   result = PDFClientSite.queryStatus(OLE.OLECMDID_OPEN);
   if ((result & OLE.OLECMDF_SUPPORTED) == OLE.OLECMDF_SUPPORTED)
    System.out.println("OLE.OLECMDID_OPEN is supported");
   else
    System.out.println("OLE.OLECMDID_OPEN is NOT supported");
   if ((result & OLE.OLECMDF_ENABLED) == OLE.OLECMDF_ENABLED)
    System.out.println("OLE.OLECMDID_OPEN is enabled");
   else
    System.out.println("OLE.OLECMDID_OPEN is NOT enabled");
 
   int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"AboutBox"});
   int dispIdMember = rgdispid[0];
   System.out.println("dispIdMember ="+dispIdMember);
   oleAutomation.invoke(dispIdMember);
 
   // Invoke the AddFile method
   // Look up the IDs of the AddFile method and its parameter
   rgdispid = oleAutomation.getIDsOfNames(new String[]{"setShowToolbar"});
   dispIdMember = rgdispid[0];
   System.out.println("dispIdMember ="+dispIdMember);
   Variant bShowToolbar = new Variant((short)1); // set to true (0 = false)
   if (oleAutomation.setProperty(dispIdMember, bShowToolbar) != true)
    System.out.println("Error: setProperty(bShowToolbar)");
 
   rgdispid = oleAutomation.getIDsOfNames(new String[]{"LoadFile"});
   dispIdMember = rgdispid[0];
   System.out.println("dispIdMember ="+dispIdMember);
//   Variant fileName = new Variant("file:///C://test.pdf"); // set to true (0 = false)
   Variant fileName = new Variant("\\test.pdf"); // set to true (0 = false)
   if (oleAutomation.setProperty(dispIdMember, fileName) != true)
    System.out.println("Error: setProperty(fileName)");
 
//   shell.pack();
   shell.open();
 
   pdfForm.setContent(PDFFrame);
 
//   if (PDFControlSite.doVerb(OLE.OLEIVERB_SHOW) != OLE.OK)
//   if (PDFClientSite.doVerb(OLE.OLEIVERB_SHOW) != OLE.OK)
//   if (PDFClientSite.doVerb(OLE.OLEIVERB_UIACTIVATE) != OLE.OK)
   boolean activated=(PDFClientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE)==OLE.S_OK);
   if(activated)
    System.out.println("Error: doVerb()");
 
   while (!shell.isDisposed())
    {
    if (!display.readAndDispatch())
     {
     display.sleep();
     }
    }
 
   oleAutomation.dispose();
   pdfForm.dispose();
   PDFFrame.dispose();
   PDFClientSite.deactivateInPlaceClient();
//   PDFControlSite.dispose();
   PDFClientSite.dispose();
  } catch(SWTError err) {
   err.printStackTrace();
  }
 

 } catch(SWTException ex) {
  ex.printStackTrace();
  // Creation may have failed because control is not installed on machine
 
  System.out.println("Error: Could Not Create PDF Control");
 
 }
  // activate the browser
 try {
 
 } catch(Exception e) {
  e.printStackTrace();
 }
}

Back to the top