Print Two Different Text Alignment on same line in Android Bluetooth thermal printer









up vote
0
down vote

favorite












so we are currently developing this app which prints receipts via bluetooth. The process is working, but our only problem is we can't print the layout that we wanted.



We wanted to print in this way:



| ID Number: 123456789|


where the left fields are default, and the right fields are generated automatically.



We tried doing work arounds but it seems like the bluetooth printer only reads one text alignment.



Here's our current code:



 align=new byte0x1B, 'a',0x00; \this is left alignment
mmOutputStream.write(align);
mmOutputStream.write(msg.getBytes());
align=new byte0x1B, 'a', 0x02; \this is right alignment
mmOutputStream.write(align);
mmOutputStream.write(msg2.getBytes());


And the output would always be the alignment on top. For example when we set the top alignment on the left. It will just display like this:



| ID Number:123456789 |


I hope you could help us guys, we've been figuring this out about a week.
Thanks! :)










share|improve this question

























    up vote
    0
    down vote

    favorite












    so we are currently developing this app which prints receipts via bluetooth. The process is working, but our only problem is we can't print the layout that we wanted.



    We wanted to print in this way:



    | ID Number: 123456789|


    where the left fields are default, and the right fields are generated automatically.



    We tried doing work arounds but it seems like the bluetooth printer only reads one text alignment.



    Here's our current code:



     align=new byte0x1B, 'a',0x00; \this is left alignment
    mmOutputStream.write(align);
    mmOutputStream.write(msg.getBytes());
    align=new byte0x1B, 'a', 0x02; \this is right alignment
    mmOutputStream.write(align);
    mmOutputStream.write(msg2.getBytes());


    And the output would always be the alignment on top. For example when we set the top alignment on the left. It will just display like this:



    | ID Number:123456789 |


    I hope you could help us guys, we've been figuring this out about a week.
    Thanks! :)










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      so we are currently developing this app which prints receipts via bluetooth. The process is working, but our only problem is we can't print the layout that we wanted.



      We wanted to print in this way:



      | ID Number: 123456789|


      where the left fields are default, and the right fields are generated automatically.



      We tried doing work arounds but it seems like the bluetooth printer only reads one text alignment.



      Here's our current code:



       align=new byte0x1B, 'a',0x00; \this is left alignment
      mmOutputStream.write(align);
      mmOutputStream.write(msg.getBytes());
      align=new byte0x1B, 'a', 0x02; \this is right alignment
      mmOutputStream.write(align);
      mmOutputStream.write(msg2.getBytes());


      And the output would always be the alignment on top. For example when we set the top alignment on the left. It will just display like this:



      | ID Number:123456789 |


      I hope you could help us guys, we've been figuring this out about a week.
      Thanks! :)










      share|improve this question













      so we are currently developing this app which prints receipts via bluetooth. The process is working, but our only problem is we can't print the layout that we wanted.



      We wanted to print in this way:



      | ID Number: 123456789|


      where the left fields are default, and the right fields are generated automatically.



      We tried doing work arounds but it seems like the bluetooth printer only reads one text alignment.



      Here's our current code:



       align=new byte0x1B, 'a',0x00; \this is left alignment
      mmOutputStream.write(align);
      mmOutputStream.write(msg.getBytes());
      align=new byte0x1B, 'a', 0x02; \this is right alignment
      mmOutputStream.write(align);
      mmOutputStream.write(msg2.getBytes());


      And the output would always be the alignment on top. For example when we set the top alignment on the left. It will just display like this:



      | ID Number:123456789 |


      I hope you could help us guys, we've been figuring this out about a week.
      Thanks! :)







      android printing bluetooth alignment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 31 '17 at 3:43









      user3060463

      116




      116






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I'm resolve that with create function like this:



          void writePrint(byte align, String msg)
          try
          mmOutputStream.write(align);
          String space = " ";
          int l = msg.length();
          if(l < 31)
          for(int x = 31-l; x >= 0; x--)
          space = space+" ";


          msg = msg.replace(" : ", space);
          mmOutputStream.write( msg.getBytes());
          catch (IOException e)
          e.printStackTrace();




          And we can use it:



          writePrint( PRINT_CENTER, "| ID Number : 123456789 |");





          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45972890%2fprint-two-different-text-alignment-on-same-line-in-android-bluetooth-thermal-pri%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I'm resolve that with create function like this:



            void writePrint(byte align, String msg)
            try
            mmOutputStream.write(align);
            String space = " ";
            int l = msg.length();
            if(l < 31)
            for(int x = 31-l; x >= 0; x--)
            space = space+" ";


            msg = msg.replace(" : ", space);
            mmOutputStream.write( msg.getBytes());
            catch (IOException e)
            e.printStackTrace();




            And we can use it:



            writePrint( PRINT_CENTER, "| ID Number : 123456789 |");





            share|improve this answer
























              up vote
              0
              down vote













              I'm resolve that with create function like this:



              void writePrint(byte align, String msg)
              try
              mmOutputStream.write(align);
              String space = " ";
              int l = msg.length();
              if(l < 31)
              for(int x = 31-l; x >= 0; x--)
              space = space+" ";


              msg = msg.replace(" : ", space);
              mmOutputStream.write( msg.getBytes());
              catch (IOException e)
              e.printStackTrace();




              And we can use it:



              writePrint( PRINT_CENTER, "| ID Number : 123456789 |");





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I'm resolve that with create function like this:



                void writePrint(byte align, String msg)
                try
                mmOutputStream.write(align);
                String space = " ";
                int l = msg.length();
                if(l < 31)
                for(int x = 31-l; x >= 0; x--)
                space = space+" ";


                msg = msg.replace(" : ", space);
                mmOutputStream.write( msg.getBytes());
                catch (IOException e)
                e.printStackTrace();




                And we can use it:



                writePrint( PRINT_CENTER, "| ID Number : 123456789 |");





                share|improve this answer












                I'm resolve that with create function like this:



                void writePrint(byte align, String msg)
                try
                mmOutputStream.write(align);
                String space = " ";
                int l = msg.length();
                if(l < 31)
                for(int x = 31-l; x >= 0; x--)
                space = space+" ";


                msg = msg.replace(" : ", space);
                mmOutputStream.write( msg.getBytes());
                catch (IOException e)
                e.printStackTrace();




                And we can use it:



                writePrint( PRINT_CENTER, "| ID Number : 123456789 |");






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 2 '17 at 7:25









                Agus Nurwanto

                1




                1



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45972890%2fprint-two-different-text-alignment-on-same-line-in-android-bluetooth-thermal-pri%23new-answer', 'question_page');

                    );

                    Post as a guest














































































                    這個網誌中的熱門文章

                    Is there any way to eliminate the singular point to solve this integral by hand or by approximations?

                    Why am i infinitely getting the same tweet with the Twitter Search API?

                    Solve: $(3xy-2ay^2)dx+(x^2-2axy)dy=0$