Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Apache POI: Saving multiple screenshots in Word document

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74727
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7233
169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74727
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic