I want implement a timed pdf in java. Basically open a pdf and have it open for any number of seconds I desire and then close automatically after the time runs out. I tried running on a thread and putting the thread to sleep that didn't seem to help. I am stuck and I cant seem to find anything online that would help me.
package testing;
import java.awt.Desktop;
import java.io.File;
/**
*
* @author xxx
*/
public class PrimeThread implements Runnable {
String name;
int time;
public PrimeThread(String x)
{
name = x;
time = 30000;
}
@Override
public void run() {
try{
System.out.printf("%s os sleeping for %d\n", name, time);
try{
File fi = new File("C:\\Users\\xxx\\Downloads\\CBP Form 3078.pdf");
Desktop.getDesktop().open(fi);
}
catch(Exception ex){
}
Thread.sleep(time);
System.out.printf("%s is done\n", name);
}
catch(Exception e){
}
}
As soon as you did Desktop.getDesktop().open(fi);
then you opened the file in your computer's default PDF viewer. At that point you no longer have any control over what is going on, it's a completely separate process.
You would need to find out what process you just created somehow and send it a kill signal or use a java PDF viewer running inside your application so you have control over it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.