-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi there, i have following problem: I got zk web application with printing function, but have problem with printing. After i click on "print" button document is sent to printer on server but i want to send it to my local printer.
this is my printing service source code:
public class PrintingServiceImpl implements PrintingService {
public void printEtiket(String harnessType, String version, String jobOrder, String date, String matrixData){
BufferedReader br = null;
String stringToPrint =null;
try {
String path=PrintingServiceImpl.class.getClassLoader().getResource("PrintingPattern.zpl").toString();
path = path.replaceAll("file:/", "");
Scanner in = new Scanner(new FileReader(path));
StringBuilder sb = new StringBuilder();
String line=null;
while (in.hasNextLine()){
line=in.nextLine();
if (line.contains("<@harnessType>")){line=line.replace("<@harnessType>", harnessType);}
if (line.contains("<@version>")){line=line.replace("<@version>", version);}
if (line.contains("<@jobOrder>")){line=line.replace("<@jobOrder>", jobOrder);}
if (line.contains("<@date>")){line=line.replace("<@date>", date);}
if (line.contains("<@matrixData>")){line=line.replace("<@matrixData>", matrixData);}
sb.append(line);
sb.append("\n");
}stringToPrint = sb.toString();
} catch (FileNotFoundException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
PrintService psZebra = null;
String sPrinterName = null;
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < services.length; i++) {
PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if (sPrinterName.toLowerCase().indexOf("gx420") >= 0) {
psZebra = services[i];
break;
}
}
if (psZebra == null) {
System.out.println("Zebra printer is not found.");
//return;
}
DocPrintJob job = psZebra.createPrintJob();
byte[] by = stringToPrint.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
job.print(doc, null);
} catch (PrintException e1) {
e1.printStackTrace();
}
}
public void printJobOrder(int id, int orderNumber, String aliasName){
BufferedReader br = null;
String stringToPrint =null;
try {
String path=PrintingServiceImpl.class.getClassLoader().getResource("PrintingPattern.zpl").toString();
path = path.replaceAll("file:/", "/");
System.out.printf("++++++++++++++++ "+path);
Scanner in = new Scanner(new FileReader(path));
StringBuilder sb = new StringBuilder();
String line=null;
while (in.hasNextLine()){
line=in.nextLine();
if (line.contains("<@jobOrderId>")){line=line.replace("<@jobOrderId>", ""+id);}
if (line.contains("<@orderNumber>")){line=line.replace("<@orderNumber>", ""+orderNumber);}
if (line.contains("<@aliasName>")){line=line.replace("<@aliasName>", aliasName);}
sb.append(line);
sb.append("\n");
}stringToPrint = sb.toString();
} catch (FileNotFoundException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
PrintService psZebra = null;
String sPrinterName = null;
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < services.length; i++) {
PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if (sPrinterName.toLowerCase().indexOf("gx420") >= 0) {
psZebra = services[i];
break;
}
}
if (psZebra == null) {
System.out.println("Zebra printer is not found.");
//return;
}
DocPrintJob job = psZebra.createPrintJob();
byte[] by = stringToPrint.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
job.print(doc, null);
} catch (PrintException e1) {
e1.printStackTrace();
}
}
}
Any ideas how to send document to my local printer? Thx for answers.
I use Jasper to create the report. Once you have the Jasper Viewer can send a print to the user. You can review the source code of iDempiere. They have all the functionality implemented thereon.
Hi Any solution on this problem ?
Asked: 2013-08-20 08:47:14 +0800
Seen: 35 times
Last updated: Jan 29 '15
Any soultion to print to local printers ?
Senthilchettyin ( 2015-01-29 04:57:32 +0800 )editHi demizon i also need the same solution. did you get it ?
Senthilchettyin ( 2015-01-29 06:21:48 +0800 )edithi, i haven't found any solution so i overcame it by sending print task to print server (network printer) not to local printer
demizon ( 2015-01-29 13:02:28 +0800 )edit