aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Taking screenshot of JSP page Using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Taking screenshot of JSP page Using java" Watch "Taking screenshot of JSP page Using java" New topic
Author

Taking screenshot of JSP page Using java

Jai babu
Greenhorn

Joined: Oct 29, 2007
Posts: 10
Hi all,

I want to take the screenshot of Jsp page in the browser. I had googled a lot. Everyone is pointing to java.awt.Robot functionality. It is great. But what i need is i want the screenshot of the full web page which is also inside the scrollable area of the browser window. Moreover i want only the webpage content not the status bar and other tabs and menus on the browser. I had used the following code.

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width-15, screenSize.height);
BufferedImage image = robot.createScreenCapture(rectangle);
ImageIO.write(image, "gif", new File("c:\\Temp\\mmgg.jpg"));

Is there a way to take the screen shot of the full JSP webpage that is viewing in the browser.(Along the content inside the scrollable window). Some tutorial points to Selenium function browser.captureEntirePageScreenshot("C:\screenshot.png","");. But not able to implement it in my JSP page which i run through tomcat and spring framework.

Thanks
Jai
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Are you trying to embed this code in a JSP page? If so, be aware that it won't work once you access the page from a machine other than the one the server runs on.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

If you want a picture of how the JSP looks in the browser on the client machine, you'll have to do something in the browser on the client machine. That would exclude Java code in the JSP, since that would run in the server. So probably you're looking at some kind of Javascript function to do that.
Jai babu
Greenhorn

Joined: Oct 29, 2007
Posts: 10
Hi all,

Thanks for your replies. Yes i agree both points. But what i need is, is it possible to take the screen shot of the full webpage displayed in the browser along with the content inside the scrollable area by using java.awt.Robot. (It should be single screenshot). If yes can anyone show me the code todo that. Otherwise as Paul Calpham said is there any javascript that take the screen shot of the webpage content inside the browser area. Please, make your valuable points to me.

Thanks
Jai
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

As this really has nothing to do with JSP, it's been moved to a more appropriate location.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jai babu
Greenhorn

Joined: Oct 29, 2007
Posts: 10
Hi,

My question is how to take screenshot of full webpage in the browser by using java.awt.Robot. I hope it comes under the topic Java/JSP.

Thanks
Jai
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
You're aware that JSPs run on the server, not in the browser, right? So if you want to use Java classes in the browser you'll need to use applets or JNLP/Java Web Start.

But what i need is i want the screenshot of the full web page which is also inside the scrollable area of the browser window. Moreover i want only the webpage content not the status bar and other tabs and menus on the browser.

I don't think it's possible to achieve either of these using the Robots class.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

You started out saying "I want..." but everybody has been assuming that you want some program to do that. If we were to interpret you literally the answer would be "Press Alt-PrtSc" and edit the result with Microsoft Paint". At any rate you haven't said anything about the context or about the actual requirement.

So here's another solution: download the JDIC code. Display your JSP in a WebBrowser component in a Java program, then have something in that Java program capture the contents of that component.

(Warning: JDIC looks like cool stuff but it's hard to configure and doesn't come with examples and was apparently abandoned about a year ago. Not for people who can't figure things out for themselves.)
Jai babu
Greenhorn

Joined: Oct 29, 2007
Posts: 10
Hello Ulf Dittmer,

Thanks for your reply. I got the problem what was it. Even if i go for Applet and embed it in he JSP page i hope it will take the screenshot of the viewable browser part but not the content inside scrollable area. Moreover it will take the desktop screenshot not the browser window only. Hope there is no other solution of taking client side screen shot of the web page in the browser with Java. If there is something todo with java please make a note of it.

Thanks
Jai
Jai babu
Greenhorn

Joined: Oct 29, 2007
Posts: 10
Hello Paul Clapham,

Its my mistake that i didn't make my problem clear. Sorry for that. I will go ahead with JDIC code. If any problem i will come back again. Please give your valuable points.

Thanks
Jai
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Jai babu wrote:Its my mistake that i didn't make my problem clear.


The main problem was that you didn't say "I want to be able to take a screenshot of a JSP in a browser" or "I want a JSP in a browser to be able to take a screenshot of itself". Those are different things. Your original post sounded like the second statement, which to me sounds like a peculiar requirement. This led me to suspect that the original requirement was actually the first statement, but that you were confused and trying to implement the second statement.

So it might be good if you paused and tried to clarify your requirement in your own mind.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Taking screenshot of JSP page Using java