• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Apache POI: Saving multiple screenshots in Word document

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Urgent] Hi Guys

I am facing some issues for the below scenario...Kindly help me out.Thanks.

My scenario is to take snapshot of our current activity every 5 seconds and append one by one in word document.

I used apache poi for handling word document and for taking snapshot using bufferedimage.

It takes snaphot every 5 seconds and pasted in generated word document only single time.for a second time, it takes snapshot and but at the time of appending in word document, it throws exception.

Please find my code snippet below and help me where i did make mistake...appreciate all your help.

public void saveScreenshot() throws Exception {


XWPFDocument docx = new XWPFDocument();
XWPFRun run = docx.createParagraph().createRun();
FileOutputStream out = new FileOutputStream("c:/fayaz/doc1.docx");

while (true)
{
String screenshot_name = System.currentTimeMillis() + ".png";
BufferedImage image = new Robot()
.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

File file = new File("C:/fayaz/" + screenshot_name);
ImageIO.write(image, "png", file);
FileInputStream pic = new FileInputStream("C:/fayaz/" + screenshot_name);


run.addBreak();
run.addPicture(pic, XWPFDocument.PICTURE_TYPE_PNG, screenshot_name, Units.toEMU(450), Units.toEMU(400));
System.out.println(screenshot_name);
pic.close();
file.delete();
docx.write(out);

try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
 
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know myself, but I recommend you avoid the word “urgent”, which people will look on as an excuse to delay replying.
 
Fayaz ali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Don't know myself, but I recommend you avoid the word “urgent”, which people will look on as an excuse to delay replying.



///sure bro...i just copied the whole text from some other forum where i posted...i make sure i avoid it...Thank you
 
Saloon Keeper
Posts: 5802
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the full stack trace of the exception, and tell us where in the code it happens.
 
Campbell Ritchie
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Fayaz ali wrote:. . . some other forum where i posted... . . .

Thank you for informing us about that; please tell the people on the other website too.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!