Results 1 to 2 of 2
  1. #1
    bronai is offline Member
    Join Date
    Jan 2009
    Rep Power

    Default Print image and send additional PCL instructions.


    I need to send an image for printing to a printer along with some printer command language code. I am using a Zebra P330i card printer.

    I find an appropriate print service using the following code:

    Java Code:
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset);
    int index = -1;
    for (int i = 0; i < services.length; i++) {
    if (services[i].getName().indexOf("Zebra") != -1) index = i;
    I have managed to send the image to the printer successfully using the Zebra printer driver and the following code, however if I append PCL code, the card image prints fine but the PCL code is not interpreted by the printer.

    Java Code:
    BufferedImage bi = CardImage.makeCardJPEG(printJob.getCardDesign(), cardholder, 1); //Method to get a BufferedImage for the card
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bi, "jpeg", baos);
    byte[] bytes = baos.toByteArray();
    aset.add(new MediaPrintableArea(0, 0, 54, 86, MediaPrintableArea.MM));
    aset.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
    services[index].createPrintJob().print(new SimpleDoc(bytes, DocFlavor.BYTE_ARRAY.JPEG, null), aset);
    If I change the driver of the printer to be 'Generic / Text' rather than the Zebra specific driver I can use the following code to send PCL commands to the printer and they are interpreted and acted upon by the printer. However then I cannot send images to the printer.

    Java Code:
    String str = "";
    str += "\u0027"; //escape char
    str += "R\r"; //reset
    str += "A\r"; //print test card
    services[index].createPrintJob().print(new SimpleDoc(str.getBytes(), DocFlavor.BYTE_ARRAY.AUTOSENSE, null), null);
    Is there a way of sending a print document to a printer including an image and PCL commands using the same printer driver?

  2. #2
    tolja is offline Member
    Join Date
    Jun 2010
    Rep Power


    I need to control this zebra p330i from java, and have same problem. Did you solve this issue, and if yes can you please explain how?

Similar Threads

  1. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 08:39 AM
  2. Canvas Image popups another image (SWT)
    By SpaceY in forum New To Java
    Replies: 2
    Last Post: 11-11-2008, 02:25 PM
  3. send documents to print queue
    By kurenai in forum Advanced Java
    Replies: 10
    Last Post: 06-26-2008, 08:47 AM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 12:04 AM
  5. Replies: 0
    Last Post: 01-08-2008, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts