Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print simplified chinese #81

Open
BanLam opened this issue May 25, 2022 · 1 comment
Open

How to print simplified chinese #81

BanLam opened this issue May 25, 2022 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@BanLam
Copy link

BanLam commented May 25, 2022

Desktop (Info):
OS: Windows 10
Lib Version 4.1.0
Java Version 1.8.0_181
Pinter: EPSON TM-m30II

code:
escpos.setCharsetName("GB2312");
escpos.writeLF("文档");

it's not working, i try all the encoding with simplified chinese already.
https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html

Thank you.
Regards.

@BanLam BanLam added help wanted Extra attention is needed question Further information is requested labels May 25, 2022
@anastaciocintra
Copy link
Owner

hi @BanLam,
its a good question about character code table,
I've saw this article https://stackoverflow.com/questions/63546719/esc-pos-termal-printer-utf-8-charset-set-up
and this doc https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=337

And for your printer, (in theory) is possible to print utf8 characters.
I can't test in mine, but you can test on tm-m30ii, if it is possible, send us feedback about test. see you.

import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.output.PrinterOutputStream;

import javax.print.PrintService;
import java.io.IOException;

public class Fs {

    public void sendData(EscPos escpos) throws IOException {
        setUtf8((escpos));
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.writeLF("文档");
        escpos.feed(5).cut(EscPos.CutMode.FULL);
        escpos.close();
    }
    private void setUtf8(EscPos escpos) throws IOException{
        final int m = 2;
        //
        //FS ( C pL pH fn m
        escpos.write(28) //FS
                .write('(') // (
                .write('C')  // C
                .write(2) // pl
                .write(0) // ph
                .write(48) // fn
                .write(m); // m
        escpos.setCharsetName("UTF8");
    }

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

        if(args.length!=1){
            System.out.println("Usage: java -jar escpos-simple.jar (\"printer name\")");
            System.out.println("Printer list to use:");
            String[] printServicesNames = PrinterOutputStream.getListPrintServicesNames();
            for(String printServiceName: printServicesNames){
                System.out.println(printServiceName);
            }

            System.exit(0);
        }
        //this call is slow, try to use it only once and reuse the PrintService variable.
        PrintService printService = PrinterOutputStream.getPrintServiceByName(args[0]);
        PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
        EscPos escpos = new EscPos(printerOutputStream);
        Fs obj = new Fs();
        obj.sendData(escpos);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants