katzer / cordova-plugin-printer

Print HTML documents
Apache License 2.0
310 stars 284 forks source link

Plugin compile Android Error (Ionic Capacitor) #274

Open lmsantanam opened 3 years ago

lmsantanam commented 3 years ago

After setting up this cordova plugin with an Ionic capacitor app, even thought is referenced in the official documentation how to be installed for capacitor:

https://ionicframework.com/docs/native/printer#installation

When I'm going to compile for Android, the plugin is throwing a lot of errors: error

So maybe this plugin is deprecated? I don't have experience with fixing plugin's internal references, so if anyone has an idea would be great

lmsantanam commented 3 years ago

Turns out the problem is with old android support dependencies (instead of using the new AndroidX equivalent). There is a workaround:

https://capacitorjs.com/docs/android/troubleshooting#error-package-androidsupport-does-not-exist

1) npm install jetifier 2) npx jetify 3) npx cap sync android

But beware, if you install any new cordova plugin for a capacitor app you need to run steps 2 and 3 again. No idea if this happens with ionic cordova, or what is the procedure when a new repo is cloned and npm i is executed for the first time

I do think that this issue shouldn't be closed and be addresed sometime. For example in the plugin for file opener this issue has been opened for a couple of years now:

https://github.com/pwlin/cordova-plugin-file-opener2/issues/256

noname181 commented 2 years ago

Hi bro, can you share your code use this plugin with Ionic capacitor, hope your help <3

lmsantanam commented 2 years ago

Hi bro, can you share your code use this plugin with Ionic capacitor, hope your help <3

Hi, no problem, what I do is like this:

1- I use another plugin (https://github.com/stephanrauh/ngx-extended-pdf-viewer) to show the pdf file in a separate page 2- I add a button on top of the page to that call a service with the printing function 3- The service validates that I'm on native platform (android or ios) 4- Then with the url to the pdf the code to print is this:

image

I do a http get with the file, then convert the result to base64, download to localstorage (to cache folder and using the FileSystem capacitor plugin) and finally the printer that is declared like this:

import { Printer } from '@ionic-native/printer/ngx';

constructor( private printer: Printer ) { }

Is kind of slow since it downloads, convert to base64 and then is triggers the print function, but I couldn't figure out another way to use this print plugin and since all my pdf are lightweight, I'm using it like that

noname181 commented 2 years ago

Thanks for your help, bro. let me try it