2

I make android app which will send PCL commands to BT printer (HP Officejet 100). Problem is when I send string data(PCL command) printer don't recognized these commands and print all these commands like normal strings. Any idea why printer don't recognize commands? My full code here: CODE

I also try change charset to US-ASCII, UTF-8 but PCL command was not recognized.

Second question: is there any way how I can convert PDF file to PCL or how I can do way when I need print PDF files on this printer?

Now I can print strings but I cannot print pdf or images etc and I find way how do this. THX for any help.

Part of code:

    void sendCustomData() throws IOException {
    try {
        String msg =
                "<ESC>%-12345X@PJL COMMENT *Start Job* <CR><LF>\n" +
                        "@PJL JOB NAME = \"Sample Job #1\" <CR><LF>\n" +
                        "@PJL SET COPIES = 1 <CR><LF>\n" +
                        "@PJL SET RET = OFF <CR><LF>\n" +
                        "@PJL ENTER LANGUAGE = PCL <CR><LF>\n" +
                        "<ESC>E. . . . PCL job . . . .<ESC>E\n" +
                        "~<ESC>%-12345X@PJL <CR><LF>\n" +
                        "@PJL EOJ<CR><LF>\n" +
                        "<ESC>%-12345X";

        mOutputStream.write(msg.getBytes("ASCII"));
        tvStatus.setText("Custom data sent");
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        closeBT();
        Toast.makeText(this, "BT conn closed", Toast.LENGTH_SHORT).show();
    }
}
pavol.franek
  • 1,396
  • 3
  • 19
  • 42
  • Pavol, did you find the anwer? TheWienke notes that you need to use the ANSI value for (0x1B), but then I don't think your code as written would write plain text either – Robert R Evans Oct 13 '16 at 13:19

2 Answers2

2

You shouldn't be using the string literal "<ESC>" because it is expecting the ASCII/UTF-8 escape character (Decimal 27, or Hex 1B). Rather, you should declare a char variable:

public final static char CHAR_ESC = 0x1B;

and use that instead

String msg = CHAR_ESC + "%-12345X@PJL COMMENT Start Job \n" + ...

TheWienke
  • 21
  • 2
0

CR and LF also should be replaced with ASCII Characters.