0

when user using my application for further use, he must be taking the screen shot of the application. When I click on the button the application screenshot need to be taken and store it in png or pdf file. Can any one tell me from where to start this. I goggled a lot.. but I didn't get any proper samples.I tried using http://html2canvas.hertzen.com/ but failed to start from hear.

Help is really appreciated..

Navyah
  • 1,660
  • 10
  • 33
  • 58
  • see if this helps : http://stackoverflow.com/questions/17825782/how-to-convert-html-to-pdf-using-itext – Balaji Krishnan Oct 09 '13 at 09:41
  • Don't you think you are trying to hack user desktop information through print screen? :) – Gyanendra Dwivedi Oct 09 '13 at 10:00
  • its not the desktop..... I want to use this in my application... when we click on print button..my application screen shot need to be done – Navyah Oct 09 '13 at 10:11
  • Application screenshot is nothing but, a **printscreen** of the destop screen, right? I mean you need to look into screen buffer and read the pixels and store in binary image format; that's in a way accessing the local hardware. If your application is a swing based desktop application, it is possible via the code logic given in the solution, but not possible, if the application is a web-based one. – Gyanendra Dwivedi Oct 09 '13 at 11:00

1 Answers1

-1

For a desktop swing application, the code might be (taken from here)

import java.awt.Robot;  
import java.awt.Rectangle;  
import java.awt.Toolkit;  
import java.awt.Canvas;  
import java.awt.Graphics;  

import java.awt.image.BufferedImage;  

import javax.swing.JFrame;  

public class CaptureScreen extends Canvas  
{  
Rectangle screenRectangle=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());  

Robot myRobot;  

BufferedImage screenImage;  

public CaptureScreen()  
{  
try  
{  
 myRobot=new Robot();  
}  
catch(Exception exception)  
{  
 exception.printStackTrace();  
}  

screenImage=myRobot.createScreenCapture(screenRectangle);  

JFrame myFrame=new JFrame("Capture Screen");  

myFrame.add(this);  

myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
myFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);  
myFrame.setVisible(true);  
}  

public void paint(Graphics g)  
{  
g.drawImage(screenImage,0,0,this);  
}  

public static void main(String[]args)  
{  
CaptureScreen cs=new CaptureScreen();  
}  
}
Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
  • Hi gyan, I want to use client side.. not from the java code.. and i am using spring in my application – Navyah Oct 09 '13 at 10:11
  • Client side screen capturing is not possible, i guess because you need to interact with client machine specific libraries and hardware, which java security architect would simply not allow to do from any code from web. That is why a swing application could do that, because it is a trusted application installed by user on the desktop, but not possible with web application. – Gyanendra Dwivedi Oct 09 '13 at 10:56
  • Hi Gyan, But my application is a web application and I need to take the screenshots of my application when ever i click the print button..I dont want to use swing concept – Navyah Oct 09 '13 at 11:27
  • I think it is not possible. Think about this, if it would been possible, any hacker can create a web application, on which as soon as user clicks, his desktop screen would reach to the hacker's machine and then boom... private information of the user compromised!!! Between downvoting of the answer is not appreciated here, at least I am devoting my time to answer you. – Gyanendra Dwivedi Oct 09 '13 at 17:42
  • You still didnt understand my requirment. I dont want desktop screen shoot,I want to keep the print button in my web application. when user click on that print button, I want to take the screenshot of my application not the desktop and save that screenshot in any folder with png or pdf file – Navyah Oct 10 '13 at 05:25
  • What is your application, I think it is what client is seeing on his browser or may be an applet (as it is a web based application).. right? – Gyanendra Dwivedi Oct 10 '13 at 05:37
  • Yes, I am using from client view – Navyah Oct 10 '13 at 06:01
  • Then what does it mean to have screenshot? Is it not the screenshot of his personal computer screen(of course along with the browser screen)? may be he has opened his secret website in another tab? Dont you think those information would be part of his screenshot (privacy breach)? – Gyanendra Dwivedi Oct 10 '13 at 08:48
  • No.. Screenshot or printscreen of the application – Navyah Oct 10 '13 at 09:06