5 Replies Latest reply on May 1, 2014 9:43 AM by Michael Toews

    Usage of new printing api in ruby

    Marcus Atkins

      Simple question, how do you use the printing api in ruby (a controller)?

       

       

       

      Have added this to build.yml :

           app_type: "rhoelements"

           extensions: ["printing"]

       

      Tried the following ways to use the printing api:

       

      Rho::Printing.getPrinterByID("xxxxxxxxxx")

      Rho::Printer.getPrinterByID("xxxxxxxxxx")

       

      Both returning "Error: uninitialized constant Rho::Printer"

        • Re: Usage of new printing api in ruby

          Hi

           

          First need to search the printer to get the printer ID.

           

          Rho::Printer.searchPrinters({ }, url_for(:action => :searchPrinters_callback));

          You can pass parameters for searchPrinters  method like printerType, connectionType, deviceAddress, devicePort to the Hash to have faster search.

           

          In searchPrinters_callback you will get the printer ID @params['printerID'].  May be need to do multiple times search if you didn’t get the printer ID in the first attempt.

           

          By using that ID you will get the printer instance as below

          @printer = Rho::Printer.getPrinterByID(@params['pid'])

           

          This instance can be used call @printer.printImageFromFile(fileURI, 50, 50, {'width' => -1, 'height' => -1}, url_for(:action => :printer_callback))

           

           

          If you include extensions: ["printing","printing_zebra"] will work for printing as well zebra specific APIs. Currently support is for zebra printers.

           

          Link for guide: http://docs.rhomobile.com/en/4.1.0/guide/printing

           

          Thanks

          Vinod Shankar

          • Re: Usage of new printing api in ruby
            Marcus Atkins

            Thank you for your response. Sorry just to clarify the issue is not how to use the specific functions in the API, but how to actually get access to the API.

             

            E.g. @printer = Rho::Printer.searchPrinters({}, url_for(:action => :printConnectionCallback))

            Gives me the error:

             

            Error: uninitialized constant Rho::Printer

            Trace:

            C:/MotorolaRhoMobileSuite4.1.1/ruby/lib/ruby/gems/1.9.1/gems/rhodes-4.1.1/lib/framework/rho/rho.rb:1243:in `const_missing'

             

            Regards,

            Marcus

            • Re: Usage of new printing api in ruby
              Marcus Atkins

              Further to this issue:

               

              The application was built in Rhodes pre RhoElements 2.2. I now utilize the webkit browser on WM devices, which I believe is only possible with RhoElements functionality? The app was migrated to RMS 2.2, then RMS 4.0, then RMS 4.1.

               

              I am confused how I am supposed to properly enable RhoElements in a pre existing (possible non-RhoElements) project. I do not have access to the magic RhoElements functionality (Rho::Printer in ruby, Rho.Printer in java script).

               

              A lot of the documentation that I have just read is quite old, confusing and possibly irrelevant now.

               

              My understanding of RhoElements was that it was an extended library for Rhodes - I believe this may not be the case at all.

               

              Any help would be greatly appreciated !

                • Re: Re: Usage of new printing api in ruby

                  Do you have a RhoElements license? You seem to be doing everything right but, if you are using app_type: "rhoelements" then you have to have a RhoElements license to build the app. If you are not building for WinMo / WinCE and you are not using any APIs that require a license, I suggest removing app_type: "rhoelements" from your build.yml.

                   

                  If you do have an RE license, you should attach the entire build log to your reply here so that we can debug further.

                   

                  Edit:

                  Now that I look at the API reference I remembered that Printing is a licensed only API. So if you do not have a license for RhoElements, you'll not be able to use the API.