Search code examples
androidiosionic-frameworkprintingcordova-plugins

how to add printer during print using cordova ionic 2 in android/ios


I want to create an application which would support native print as shown in the picture.

android native print ui

Does ionic 2/3 support this kind of feature?

I have come across https://github.com/katzer/cordova-plugin-printer

Although I doubt this support prints outside the application. I have to still print even the document has opened from a different application.


Solution

  • I had to install the native print plugin and then extend an android PrintService, which will add my printer in the list.

    had to add PrinterCapabilitiesInfo printerCapabilitiesInfo = new PrinterCapabilitiesInfo.Builder

    PrinterInfo printerInfo = new PrinterInfo.Builder

    To generate the printer capabilities and add this to

    printerInfoList.add(printerInfo)

    the following got me the file.

    @Override protected void onPrintJobQueued(PrintJob printJob) { final File file = getFile(printJob);

        final Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.fromFile(file));
        startActivity(intent);
    
        printJob.cancel();
    }