dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

In android 13 Printing.convertHtml() function not working. App got stuck at that point and generate nothing!

Open bhaumik1111 opened this issue 1 year ago • 34 comments

Describe the bug

i have other device samsung c7 pro(android version 8) and in that device this function works perfectly fine but got error in my other device samsung m34.

i share below code i call this lines of code it will print htmlToParse:-"

Hello!

" then i wait for a 5 min but this function doesn't return any thing in htmlString variable!

App got stuck at Printing.convertHtml(htmlToParse).

i use printing: ^5.11.0 my flutter sdk 3.10.5

To Reproduce Code snippet to reproduce the behavior:



htmlToParse="<html><body><p>Hello!</p></body></html>";
            print("htmlToParse:-$htmlToParse");
            htmlString = await Printing.convertHtml(html: htmlToParse);
            print("htmlString:-$htmlString");
            

how can i solve this issue ??

bhaumik1111 avatar Oct 30 '23 15:10 bhaumik1111

Same issues, it is working in Android 13 Samsung, but stuck in Android 13 Google Pixel, i'm tried debug it, in Java method adatapter.write - not response

mozomig avatar Nov 01 '23 11:11 mozomig

in android 13 device working? which device?

bhaumik1111 avatar Nov 01 '23 11:11 bhaumik1111

in android 13 device working?

I have 2 device with 13 Android, Google Pixel and Samsung s22 ultra, and in Samsung that work perfrectly but in Google Pixel method convertHtml is not work it stuck

mozomig avatar Nov 01 '23 11:11 mozomig

can you share code? just that function!

bhaumik1111 avatar Nov 01 '23 11:11 bhaumik1111

same problem here

andersonmendess avatar Nov 01 '23 13:11 andersonmendess

after uninstall the webview update (https://play.google.com/store/apps/details?id=com.google.android.webview) it working again.

andersonmendess avatar Nov 01 '23 13:11 andersonmendess

Means issue resolve in your app?

bhaumik1111 avatar Nov 01 '23 13:11 bhaumik1111

after uninstall the webview update (https://play.google.com/store/apps/details?id=com.google.android.webview) it working again.

thanks, it is work for me, bug in webview system it is very funny :D

mozomig avatar Nov 01 '23 14:11 mozomig

Means issue resolve in your app?

it is not application issue, it is issue android webview component in devices, all people who get this bug should be remove update android webview component in system.

I think this issue can be close because library make all good

mozomig avatar Nov 01 '23 14:11 mozomig

But how?? Can you pls provide step to solve I am new to flutter so

Actually i also use webview_flutter for webview content in my app

bhaumik1111 avatar Nov 01 '23 14:11 bhaumik1111

But how?? Can you pls provide step to solve I am new to flutter so

Actually i also use webview_flutter for webview content in my app

In device where it is not work, need open https://play.google.com/store/apps/details?id=com.google.android.webview and click button "remove" thats all, dart pdf use PdfDocumentAdapter with system WebView

mozomig avatar Nov 01 '23 15:11 mozomig

@mozomig that's not the solution! for app it is not good say to user uninstall the android webview from playstore and it works

need to find solution from library side!

bhaumik1111 avatar Nov 03 '23 11:11 bhaumik1111

@mozomig that's not the solution! for app it is not good say to user uninstall the android webview from playstore and it works

need to find solution from library side!

Yep, you can write issue for Google, when they fixed webview component and updated it, this issue will be fixed :) it is not issue this library it is issue webview, we don't have solution for fixed in library side it is impossible

mozomig avatar Nov 03 '23 13:11 mozomig

Does anyone know if there is any ticket that we can track regarding this Android system webview bug? I tried with Android system webview beta and dev and they are also not working, so it is not looking good so far.

savs90 avatar Dec 07 '23 08:12 savs90

there is no other option so uninstall Android system webview from device and it will work

bhaumik1111 avatar Dec 07 '23 08:12 bhaumik1111

I did it, but this can't be a serious permanent solution?

savs90 avatar Dec 07 '23 08:12 savs90

i also discuss this point in previous chat. Now what is the permanent solution that i don't know. i am also new in flutter so waiting for solution

bhaumik1111 avatar Dec 07 '23 08:12 bhaumik1111

I think I'll remove this convertHtml function and point people to another library to do the same thing.

It's not available on all platforms and the result is not consistent. There are bug reports that cannot be fixed because they use the system's WebView to render the HTML, which is vendor-specific.

DavBfr avatar Dec 07 '23 11:12 DavBfr

Any update on this?

HAFIZkhan-source avatar Jan 09 '24 12:01 HAFIZkhan-source

Not yet brother!! Developer says android webview side issue and he is right bcoz in ios its working fine!! So need to wait for android side or library side solution!!

bhaumik1111 avatar Jan 09 '24 18:01 bhaumik1111

@bhaumik1111 But Need to resolve this issue from this package side only. As an app developer, we can't tell app users to remove android system webview update from their phone to use this package based feature

HAFIZkhan-source avatar Jan 10 '24 09:01 HAFIZkhan-source

Any update on a potential fix and/or alternative library?

jelen-HC avatar Jan 31 '24 15:01 jelen-HC

No brother! @jelen-HC

bhaumik1111 avatar Feb 01 '24 09:02 bhaumik1111

I think I'll remove this convertHtml function and point people to another library to do the same thing.

It's not available on all platforms and the result is not consistent. There are bug reports that cannot be fixed because they use the system's WebView to render the HTML, which is vendor-specific.

It will be unfortunate if this functionality is dropped. This is the only option to get a decent PDF that looks the same as the original html in a webview. The suggested alternative is not anywhere close to that and is broken in many ways.

In my tests the current Printing.convertHtml() works on iOS, MacOS and Android below 13. Unfortunately it does not work on Android 13 and 14.

However there is a html_to_pdf which is also using Android's webview for html to PDF rendering but works on Android 13 and 14.

After a quick comparison I came up with this change below and with this change the Printing.convertHtml() now also works on Android 13 and 14 in my tests.

Hopefully you could use this and consider reverting deprecation of this essential feature.

image

ekuleshov avatar Feb 24 '24 19:02 ekuleshov

@ekuleshov I see. Maybe I can move this code to a new package. This way it's opt-in and obvious that it doesn't work with Windows, Linux, and web.

DavBfr avatar Feb 24 '24 19:02 DavBfr

@ekuleshov I see. Maybe I can move this code to a new package. This way it's opt-in and obvious that it doesn't work with Windows, Linux, and web.

Don'y you already have Printing.info() declaring supported capabilities? This doesn't seem different from canRaster or canPrint.

ekuleshov avatar Feb 24 '24 19:02 ekuleshov

Still, people report as a but that it doesn't work on some platforms, without checking Printing.info().

DavBfr avatar Feb 24 '24 19:02 DavBfr

I suppose you can throw an exception saying that feature X is not supported on the current platform. That could be the same of all flags in the PrintingInfo.

~~BTW, for the web support you might be able to use html2pdf.js - it works with jsPDF, which I think you also using.~~

ekuleshov avatar Feb 24 '24 19:02 ekuleshov

For the web support it seems like jsPDF works well.

It needs these two dependencies:

<script src="jspdf.umd.js"></script>
<script src="html2canvas.js"></script>

then the following js code produces a very decent PDF document:

window.jsPDF = window.jspdf.jsPDF;
var doc = new jsPDF();
doc.html(document.body, {
   callback: function (doc) {
     doc.save();
   },
   width: 135,
   windowWidth: 600
});

ekuleshov avatar Feb 25 '24 14:02 ekuleshov

+1 to fix the problem and revert the deprecation...

dr953 avatar Mar 07 '24 07:03 dr953