Skip to Content
Author's profile photo Daniel Van Leeuwen

Getting Started with Kapsel – Part 19 — Printer

          /wp-content/uploads/2015/01/sap_logo_624838.png

Printer (New in SP06)

This plugin enables the ability to print using AirPrint on iOS and the Android Printing Framework on Android 4.4 or higher devices.  It uses the open source Printer plugin.

For additional details on the Kapsel Printer plugin see the JavaScript file in a project that includes this plugin at

project_name\plugins\de.appplant.cordova.plugin.printer\www\printer.js

or the JS Documentation at Kapsel Printer API Reference.

The following steps will demonstrate using this plugin.

  • Create the project.
    cordova -d create C:\Kapsel_Projects\PrinterDemo com.mycompany.printer PrinterDemo "{\"plugin_search_path\":\"C:/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd C:\Kapsel_Projects\PrinterDemo
    cordova -d platform add android
    
    cordova -d create ~/Documents/Kapsel_Projects/PrinterDemo com.mycompany.printer PrinterDemo "{\"plugin_search_path\":\"/Users/i826567/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd ~/Documents/Kapsel_Projects/PrinterDemo
    cordova -d platform add ios
  • Add the Kapsel or open source printer plugin.
    cordova -d plugin add de.appplant.cordova.plugin.printer or cordova -d plugin add https://github.com/katzer/cordova-plugin-printer.git 
  • Replace www\index.html with the contents of index.html.
  • Copy the files to the platform directory by running
    cordova -d prepare
  • Use the Android IDE or Xcode to deploy and run the project.

    The Print Original Page passes the location.href to the print method while Print Current Page passes document.body which includes the logged messages such as Printer is available.  Notice that thedate text input is empty either way.  Finally the Print Other Page prints the current weather forecast in Waterloo Ontario (http://weather.gc.ca/city/pages/on-82_metric_e.html).

    The following demonstrates how to view the results of printing a page on an Andoid emulator and an iOS simulator. Press the Is Printer Available button and then the Print Current Page.

    image1.PNGimage2.PNGimage3.PNGimage4.PNGimage5.PNG

    To download the Printer Simulator, in Xcode, choose Xcode > More Developer Tools… > Hardware IO TOols for Xcode – Xcode 6.1.
    Once downloaded start the Printer Simulator.  Note if an error appears in Xcode while attempting to print, the following may help.  AirPrint Connection Refused Error.

    image6.PNGimage7.PNGimage8.PNG

Back to Getting Started With Kapsel

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo saket amraotkar
      saket amraotkar

      Hi Daniel,

      Very nice document.

      Is there any API available which will print reports from windows 8.1 platforms to bluetooth printers?

      We are developing SAPUI5 application which will be packaged in Cordova container, i searched KAPSEL/Cordova, but no API to print for Windows 8.1 platforms.

      Can you please help me in this regard.

      Regards

      Saket

      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen
      Blog Post Author

      I don't believe Kapsel/SMP SDK provides this in the SP08 release.

      http://help.sap.com/saphelp_smp308sdk/helpdata/en/10/e4e12b7a7d4de3a2b80c9c935aded2/content.htm

      I suppose you could look for an open source plugin to provide this.  I have not myself used one on Windows.

      Regards,

      Dan van Leeuwen

      Author's profile photo Marius Stoica
      Marius Stoica

      Hi Daniel,

      I'm trying to print the some data from my Cordova app to a bluetooth printer imZ320 but I get an error.

      10-30 12:03:45.875: E/AndroidRuntime(26534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 10-30 12:03:45.875: E/AndroidRuntime(26534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

      I've tried to do some debug on the issue and I found that the exception message is:

      No Activity found to handle Intent { act=android.intent.action.SEND typ=image/png pkg=com.zebra.android.zebrautilities }

      Now let me tell you what I've installed (nothing modified just open source code). 1. Printer app -http://scn.sap.com/docs/DOC-61345 2. Cordova Kapsel plugin - https://github.com/katzer/cordova-plugin-printer/tree/network-printer (I know it said "deprecated" but I need to make something work on my device). By default the plugin from the SCN message send the "object" to the Android print server and creates a PDF file. In my case I need o send it to a real printer, ergo imZ320 and the network-printer.

      The intent is created in the function below (found in the print.java file of the plugin):

      private Intent getPrintController (String appId) { String intentId = "android.intent.action.SEND";

      Other sources that I found that work (but native apps created): https://km.zebra.com/kb/index?page=content&id=WH62 and https://opendatakit.org/downloads/download-category/sensors-and-printers/

      I tried to reverse engineer them but with no luck 🙁

      And here is a related plugin that I found on github to zebra printing, but couldn't make it do anything:https://github.com/mchapper/cordova-plugin-zebra-printer/

      Regards,

      Marius

      Author's profile photo Former Member
      Former Member

      Any new about the support of this plugin in Windows 8.1?

      Thank you!

      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen
      Blog Post Author

      There is a table at the link below that mentions Windows 8.1.

      http://help.sap.com/saphelp_smp3011sdk/helpdata/en/98/c5d867767f4db387983c49dd5cca23/content.htm?frameset=/en/ed/65d7f0acbd4ae2bb4bb59e0aa389ad/frameset.htm&current_toc=/en/7c/01cda6700610149b10c2f2a86d335b/plain.htm&node_id=618&show_children=false

      Updating the content displayed in this section is on my todo list 🙂

      Note, the version that I will be updating is.

      Getting Started with Kapsel - Part 14 -- Printer (SP09+)

      Regards,

      Dan van Leeuwen

      Author's profile photo Former Member
      Former Member

      Hi Daniel

      When i click on the index.html file as you said i am getting page not found . Kindly send me the link where i can the index.html code

      Regards
      Ashwin

      Author's profile photo Daniel Van Leeuwen
      Daniel Van Leeuwen
      Blog Post Author

      This blog post was archived and covers an early version of the Kapsel SDK.  Please see https://blogs.sap.com/2015/07/20/getting-started-with-kapsel-part-14-printer-sp09/ or for the very latest version of the blog series see https://blogs.sap.com/2016/10/20/getting-started-kapsel-part-1-sp13/

      Regards,

      Dan van Leeuwen