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]
# 1

and this has what to do with programming in the java language? am I missing something here?

petes1234a at 2007-7-28 19:23:53 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

miryalaa at 2007-7-28 19:23:53 > top of Java-index,Java Essentials,Java Programming...
# 3

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

BugBunnya at 2007-7-28 19:23:53 > top of Java-index,Java Essentials,Java Programming...
# 4

Thnks for the reply. Yes 'lpr' is an unix command.

Is there any other go for this?

miryalaa at 2007-7-28 19:23:53 > top of Java-index,Java Essentials,Java Programming...
# 5

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();

}

java_2006a at 2007-7-28 19:23:53 > top of Java-index,Java Essentials,Java Programming...