Sorry for the duplicate post but forgot to post this as a question...
I am using JExplorer 1.9, Windows XP Pro, IE7, JDK 1.5.0_14 and Adobe Acrobat Reader v8.0.
My browser automation app clicks a link to a PDF file. A new child window pops up that needs to be resized (can't even see any content). I want to resize the window so the PDF is viewable and then take a screenshot. When I resize the window using:
child.getgetTopLevelAncestor().setBounds(0, 0, 1000, 800);
The resize works but the window does not repaint the PDF content - just get a gray colored empty window. I tried adding a child.refresh() but it didn't work. If I put in a sleep after the child pops up I can manually resize the window and it repaints the PDF properly. Is there a way to specify a window size for children BEFORE they are opened? This would be very helpful rather than resizing after the window is opened.
Another problem is I get a NullPointerException when I try to take a screenshot of this window:
Exception in thread "main" java.lang.NullPointerException
at com.jniwrapper.win32.ie.dom.e.getElementsByTagName(SourceFile:233)
at com.jniwrapper.win32.ie.dom.e.b(SourceFile:461)
at com.jniwrapper.win32.ie.dom.e.getBody(SourceFile:479)
at com.jniwrapper.win32.ie.dom.e.c(SourceFile:528)
at com.jniwrapper.win32.ie.dom.e.getHorisontalScrollPosition(SourceFile:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.jniwrapper.win32.ie.dom.j.run(SourceFile:592)
at com.jniwrapper.win32.MessageLoopThread$ThreadSynchronizedAction.run(MessageLoopThread.java:569)
at com.jniwrapper.win32.MessageLoopThread$LoopThread.run(MessageLoopThread.java:511)
Any help you can provide to get this working would be greatly appreciated.
Hello,
1. In order to resize child window correctly you need to call the validate() method too. For example:
browser.addNewWindowListener(new NewWindowEventListener()
{
public void windowOpened(WebBrowser webBrowser)
{
Container ancestor = ((Browser) webBrowser).getTopLevelAncestor();
ancestor.setBounds(0, 0, 1000, 800);
ancestor.validate();
}
});
2. The WebBrowser.getScreenShot() method can be used only for making screenshot of a HTML web page. This method is not implemented for taking screenshot of an Acrobat Reader document embedded into Browser component.
Regards,
Vladimir Ikryanov
Thank you Vladimir. The validate() call after resizing works perfectly and the PDF reader/document can be seen nicely.
I am now having trouble closing the child window that displays the PDF. When child.close() is first called the Acrobat reader content goes away and the window content area is empty but the window will not close. If I close the window using the "X" control in the upper right corner I get the following NPE. I am simply calling child.close() where child is the return from browser.getRecentChild(). Is this the wrong way to close this browser window?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.jniwrapper.win32.ie.Browser.close(SourceFile:639)
at com.jniwrapper.win32.ie.af.run(SourceFile:871)
at com.jniwrapper.win32.ie.Browser.a(SourceFile:175)
at com.jniwrapper.win32.ie.Browser.a(SourceFile:34)
at com.jniwrapper.win32.ie.ae.windowClosing(SourceFile:865)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Hi,
In order to programmatically close child window you need just to dispose its window. For example:
Container ancestor = ((Browser) child).getTopLevelAncestor();
((JFrame) ancestor).dispose();
The reason of NPE you receive is that actually the WebBrowser.close() method is invoked twice. At first you invoke this method directly and then this method is invoked automatically when you press the "X" button on child browser window.
Regards,
Vladimir Ikryanov