2 Replies Latest reply on Jul 9, 2018 5:52 AM by mahmoud zahran

    print an image and text to receipt using cpcl in android  MZ320

    mahmoud zahran

      Dear all,
      I tried to print image and text in receipt using Cpcl format like that template. I have an example set logo as a variable and use function to read the image as string but that image in example is CPCL format I tried a lot  to get my logo as a cpcl format but i can't so I need to know how to get my image logo as cpcl format or another way to set image and text like that templete.

      ====================================================

      ! 0 200 200 1050 1

      PW 575

      TONE 0

      SPEED 3

      ON-FEED IGNORE

      NO-PACE

      BAR-SENSE

      BT 0 4 6

      B 128 3 30 120 20 0 ${barcode}

       

      PCX 420 790 ${Logo}

       

      ML 32

      T270 7 0 550 170 ${typeTicket}

      ENDML

       

      ML 32

      T270 7 0 498 170 ${validPeriod}

      ENDML

       

      ML 25

      T270 7 0 446 170 ${park}

      ENDML

       

      ML 32

      T270 7 0 370 170 ${price}

      ENDML

       

      ML 25

      T270 7 0 300 170 ${termsOfUse}

      ENDML

       

       

      PRINT

      =================================

      this is the code used to read image as a string and it works perfectly with the example.

       

      this line how to use !

      result = StringUtils.replace(result, "${Logo}", PrinterUtil.readFormat(context, R.raw.logo));

       

      public static String readFormat(Context context, int formatRes) {

        InputStream is = null;

         try {

        is = context.getResources().openRawResource(formatRes);

         try {

         return readString(is);

        } catch (IOException e) {

         return null;

        }

        } finally {

         if (is != null) {

         try {

        is.close();

        } catch (IOException e) {

        }

        }

        }

      }

        • Re: print an image and text to receipt using cpcl in android  MZ320
          Robin West

          Hi Mahmoud, the easiest way to convert the image to CPCL format is to use the SDK.

          1. First you need to use the connection to create a CPCL ZebraPrinter object.
          2. Start sending your format.
          3. Use the printImage method as an embedded image
          4. Finish sending your format

           

          import java.io.IOException;

           

          import com.zebra.sdk.comm.Connection;

          import com.zebra.sdk.comm.ConnectionException;

          import com.zebra.sdk.comm.TcpConnection;

          import com.zebra.sdk.printer.ZebraPrinter;

          import com.zebra.sdk.printer.ZebraPrinterFactory;

          import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;

           

          public class GraphicsUtilExample {

           

               public static void main(String[] args) throws Exception {

                   Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);

                   try {

                       connection.open();

                       ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL, connection);

                   // send the first part of your format

                       int x = 0;

                       int y = 0;

                       int width = 0;

                       int height = 0;

                       printer.printImage("/sdcard/sample.jpg", x, y, width, height, true );

                  // send the end of your format

                   } catch (ConnectionException e) {

                       e.printStackTrace();

                   } catch (ZebraPrinterLanguageUnknownException e) {

                       e.printStackTrace();

                   } catch (IOException e) {

                       e.printStackTrace();

                   } finally {

                       connection.close();

                   }

               }

           

          }

            • Re: print an image and text to receipt using cpcl in android  MZ320
              mahmoud zahran

              I tried your solution but it doesn't work with me I tried a lot of solution but it doesn't  work too.
              I have old code use image as afile in cpcl extention instead of png or jpg I don't know how it comes?
              but I created new solution when i searched in documentation i found that command and i did it using the blow steps.

              How to change logo in Ticket using CPCL in  Android app?

               

               

               You have to follow these steps to change it and make it work with Zebra printer MZ320 & iMZ320:

                   o At the first you have to change your image to black & white image using this link. http://pinetools.com/threshold-image.

                   o After that you have to get it as binary text from its pixels and resize it using custom width =120 using this link https://www.dcode.fr/binary-image .

                   o Copy binary text that you exported from image and paste it into text editor like notebad++.

               

               

               Change all (1) ones in the image to (F) capital letter.

               your_ticket.cpcl Then you have to use this command into it “EXPANDED-GRAPHICS [ByteWidth] [Height] [X] [Y] [Data]<CR><LF>”.

               ByteWidth is size of bytes of first line in your data like that example below.

               Height is the number of lines in your data

               Data is the image data copy it from text editor and write it like that example.

               Example:

               

              EXPANDED-GRAPHICS 10 6 30 30
              FFFFFFFFFFFFFFFFFFFF
              FFFFFFFFFFFFFFFFFFFF
              FF0000FFFFFFF00000FF
              FF00000FFFFF000000FF
              FF000000FFF0000000FF
              FFFFFFFFFFFFFFFFFFFF<CR><LF>

               

               

                      o Test your image data and print ticket if you find that your image not clear try to rotate it 35 degree to right like that image.