Document d=new Document();
PdfWriter.getInstance(d, new FileOutputStream("op.pdf"));
d.open();
Image img1 = Image.getInstance("hellsing.jpg");
d.add(img1);
d.close();
Here you will find lots of code [JAVA & JAVASCRIPT] & some links that are useful for web development and stand alone projects in java. If you need more contact me on my email.
5/2/09
To start a process with ProcessBuilder
try {ProcessBuilder proc = new ProcessBuilder("notepad.exe", "testfile");
proc.start();
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
To open a file in it's editor [Default]
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] a) {
try {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.edit(new File("hellsing.jpg"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] a) {
try {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.edit(new File("hellsing.jpg"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Code for Browsing a Site when uninstalling of installing Application
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class Main {
public static void main(String[] a) {
try {
URI uri = new URI("http://www.java2s.com");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
if (desktop != null)
desktop.browse(uri);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (URISyntaxException use) {
use.printStackTrace();
}
}
}
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class Main {
public static void main(String[] a) {
try {
URI uri = new URI("http://www.java2s.com");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
if (desktop != null)
desktop.browse(uri);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (URISyntaxException use) {
use.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)