0

printing from server on local printer

asked 2013-08-20 08:47:14 +0800

demizon gravatar image demizon
179 1 6

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.

delete flag offensive retag edit

Comments

Any soultion to print to local printers ?

Senthilchettyin ( 2015-01-29 04:57:32 +0800 )edit

Hi demizon i also need the same solution. did you get it ?

Senthilchettyin ( 2015-01-29 06:21:48 +0800 )edit

hi, 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

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-08-20 15:31:51 +0800

acanaveral gravatar image acanaveral
1 1

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.

link publish delete flag offensive edit
0

answered 2015-01-29 06:22:39 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi Any solution on this problem ?

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-08-20 08:47:14 +0800

Seen: 35 times

Last updated: Jan 29 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More