我如何使用bixolon打印机打印波斯语

时间:2018-07-31 13:37:31

标签: android printing bixolon-printer

我在此应用程序中为android创建了一个应用程序,我连接到bixolon(350plusll)打印机,并且当我的String用英语显示时可以打印tiket,并且我的tiket打印良好,但是当我的String用波斯语时我可以打印结果不好,我的字符反转了并且不正确

我使用屏幕快照还可以,但是非常慢,并且不逻辑

请帮助我解决此问题

非常感谢

enter image description here

这是我的代码

package com.example.bahram.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.bixolon.printer.BixolonPrinter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class PrintTicketActivity extends Activity {

    Button btn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_print_tiket);

        btn= findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //I set code page of the printer here because i want the printer print persian so i set that on Farsi
                MainActivity.mBixolonPrinter.setSingleByteFont(BixolonPrinter.CODE_PAGE_FARSI);
                //i have a file it's name is new2.txt and readContentOfFile is a method which read all of text in new2.txt and at last print data on the paper
                MainActivity.mBixolonPrinter.printText(readContentOfFile(),BixolonPrinter.ALIGNMENT_CENTER,BixolonPrinter.TEXT_ATTRIBUTE_FONT_A,BixolonPrinter.TEXT_SIZE_HORIZONTAL1,true);
            }
        });

    }

    //read all of the text in new2.txt and return text
    String readContentOfFile() {
        StringBuilder text = new StringBuilder();

        InputStream inputStream = getResources().openRawResource(R.raw.new2);

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String line;

            while ((line = br.readLine()) != null) {
                text.append(line);
                text.append('\n');
            }
            br.close();
        } catch (IOException e) {
            //You'll need to add proper error handling here
        }

        return text.toString();
    }
}

new2.txt的内容是底部文本

اماجدیدترینشاهکارسازمانلیگوهیاتفوتبالاستانتهرانکهازسویهمینسازمانلیگبهعنوانبرترینهیاتایرانانتخابشد,جانماییتوپشروعمسابقهرویقیف(یاکنز)بودکهدردیدارسایپاوپیکانصورتگرفت

1 个答案:

答案 0 :(得分:0)

您可以使用Bixolon打印机可用的波斯语选项之一,例如以下一项:

// Farsi option : Mixed
MainActivity.mBixolonPrinter.setFarsiOption(BixolonPrinter.OPT_REORDER_FARSI_MIXED);

// Farsi option : Right to Left
MainActivity.mBixolonPrinter.setFarsiOption(BixolonPrinter.OPT_REORDER_FARSI_RTL);