hi friends
I need to print *.PRN file from java code.*
I need to print directely without open printer dialog box when i select .PRN file then it should able to direct print to default printer.
Here is the Dos command to directely print the PRN file
COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ
(source: http://filext.com/faq/print_from_prn_file.php)
i try to run that dos command through Process p = Runtime.getRuntime().exec("COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ");
But is show that
Here is the LOG of ERROR
\\java103\HP LaserJet M1120 MFP
java.io.IOException: Cannot run program "COPY": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Print2Printer.GetDefaultPrinter.main(GetDefaultPrinter.java:17)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Here is the Source
import java.io.IOException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class GetDefaultPrinter {
public static void main(String args[]){
PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(printer.getName());
try {
Process p = Runtime.getRuntime().exec("COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ");
System.out.println(p);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}