Print PDF file using LP Command
Hi all,
I need to print pdf files by using lp command on UNIX server. Iam using J2sdk1.4.
I need to use the following lp command in the function to print:
lpr -P <printername> <filename>
Can any one give me the code for this.
[263 byte] By [
miryalaa] at [2007-11-27 10:43:07]

I need to write java function which takes two input parameters. In that function I need to call lp command.
1) Name of the Printer
2) Name of the pdf file to print
If I call this newly created function, the pdf file should send to the given printer for printing.
Hmm
my wild guess:
String cmd = new String[4];
cmd[0] = path+"lpr"; // is this an exe in UNIX? no idea...
cmd[1] = "-P";
cmd[2] = printername;
cmd[3] = filename;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
but maybe im totally wrong...
BugBunny
try this:
String pdfPath="PDF_ABSOLUTE_PATH";
String printer="YOUR_PRINTER_NAME";
try {
String cmd = "lp -d " + printer + " " + pdfPath;
Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd });
} catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}