Open FisherWL opened 4 years ago
Any update on this? I need this feature too.
I am using in production pdf_viewer_plugin and it works nice for me.
It also supports embedded previews.
i also have this issue i tried adding android:usesCleartextTraffic="true" to the application tag in the manifest to no avail
This bug exists and is tracked here #41185 . There have a discussion about this and possible solutions. Please close this problem if it is duplicated. @FisherWL @VladyslavBondarenko
Closing mentioned because current issue has more participants.
Persists with dev 1.19.0-1.0.pre
.
My solution on this is converting PDF to .svg, then embed .svg into webview. Then you'll face an issue that on Android you can't pinch to zoom on that .svg/webview, my solution on that is https://github.com/flutter/plugins/pull/2451 For some reason, this PR is not reviewed yet.
I have a same problem. In using webview and my page is load correct. This page have links to open pdf e when I click this link nothing happening.
Someone have a idea to solve this issue?
I am able to replicate this issue on dev channel (1.20.0-0.0.pre)
using latest version of webview_flutter
. I tried on Android Samsung galaxy device and the said pdf doesn't open on screen launch as no action takes place.
Does anyone have a solution to this problem? I also absolutely need this feature. Everything works fine in iOS.
experiencing the same problems as mentioned above.
Experiencing the same issue. Any update on a solution?
Please, stop commenting on problems things like at:
any update on this
The best option is to add this emoji :+1: in the initial comment. To see a priority of each issue, we can see in which Milestone the issue is added.
Thanks
Please, stop commenting on problems things like at:
any update on this
The best option is to add this emoji 👍 in the initial comment. To see a priority of each issue, we can see in which Milestone the issue is added.
Thanks
Moreover, when a working solution has already been mentioned above.
Just use https://pub.dev/packages/pdf_viewer_plugin when you detect that pdf is about to be opened. It also supports embedded previews.
Please, stop commenting on problems things like at:
any update on this
The best option is to add this emoji 👍 in the initial comment. To see a priority of each issue, we can see in which Milestone the issue is added. Thanks
Moreover, when a working solution has already been mentioned above.
Just use https://pub.dev/packages/pdf_viewer_plugin when you detect that pdf is about to be opened. It also supports embedded previews.
Gotta love those patronising comments without any proper solutions! The issue I raised that has been bundled into this one is that links don't open when clicked on a webpage. The package you refer to states something quite different hence it's of no use:
pdf_viewer_plugin 1.0.0+2 Published Sep 17, 2019 FLUTTER ANDROID IOS 22 → Metadata A Flutter plugin for IOS and Android providing a simple way to display local file PDFs
As you can see, the issue is different: it's not about local pdfs, but Links to pdfs from an opened webpage...
@willvlad I was using this package for the network PDFs for quite a long time in production with no issues. You can use flutter_cache_manager to download the file and the open it (you need to transfer those bytes either way).
File file = await DefaultCacheManager().getSingleFile(url);
filePath = file.path;
If you want to handle links from opened webpage, then listen for the navigation event, I believe in this library it could be done like this (inspired by https://pub.dev/packages/webview_flutter/example):
navigationDelegate: (NavigationRequest request) {
if (request.url.endsWith('.pdf')) { // or use regex if your links include query params too
// push new screen with pdf viewer plugin
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
I agree that it's not enough to close this issue but at least it solves the problem for most of the people, doesn't it?
This navigationDelegate property is actually quite helpful. Thanks for finding it. I wonder if there is a similar one in flutter_webview_plugin, the docs don't seem to mention anything similar. We're using that one rather than flutter_webview, which is prone to crashing our Android app whenever there are complex forms, something that doesn't happen with the community version. In any event, this navigationDelegate prop has given me an idea how one can do a workaround without using any other plugin: just push another webview substituting the requested pdf url with 'https://docs.google.com/gview?embedded=true&url=${request.url}'. Could be a decent workaround for anyone with a similar use case, until webview is able to open pdf natively
Thanks @willvlad My solution is:
navigationDelegate: (NavigationRequest request) { if (request.url.endsWith('.pdf')) { // or use regex if your links include query params too // push new screen with pdf viewer plugin Navigator.push( context, MaterialPageRoute( builder: (context) => VediPDF(url:'https://docs.google.com/gview?embedded=true&url=${request.url}')), ); return NavigationDecision.navigate; } return NavigationDecision.navigate; },
Create VediPDF with new WebView with parameter url
Is there a fix planned for it?
For those using flutter_webview_plugin instead, here's the @jans-y solution adapted for this package. I'm using the open_file package to let android handle document opening for me:
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
if (viewState.url.contains('.pdf')) {
_openPdf(viewState.url);
}
}
...
Future<void> _openPdf(String url) async {
final file = await DefaultCacheManager().getSingleFile(url);
OpenFile.open(file.path);
}
If your file requires authentication to download, you can set cookies using the header parameter like this:
final file = await DefaultCacheManager().getSingleFile(
url,
headers: {
'cookie': 'cookie_name=cookie_value',
},
);
Hope it helps 👍🏼
I understand the real problem is that it doesn't return any errors, so we can't manage the pdf display.
If the Webview returned an error when trying to load url with pdf, it could be managed with another plugin.
Any suggestion?
Thanks @albertopaganuzzi , but sometimes docs viewer is not showing the doc, for that my solution is `WebView( initialUrl: 'https://docs.google.com/viewer?url=${request.url}', javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (webController) { webViewController = webController; }, onPageFinished: (url) async { if(webViewController != null){ var title = await webViewController.getTitle(); if (title.isEmpty) { webViewController.reload(); } }
},
)`
following - any planned fix here?
Will this issue be fixed?..
Retitling; the fact that PDF isn't displayed is a function of the platform webview itself, but we should look into whether we can provide APIs to allow graceful handling of this within client applications.
That would be nice. None of the suggested workarounds with special treatment for PDF links works if the PDF is hosted in binary form without the .pdf ending. This forces you to exit the app and use an external browser to handle such cases.
The issue is reproducible on master 2.5.0-6.0.pre.40
and stable 2.2.3
with webview_flutter: ^2.0.10
.
I'm having the same issue here. When using webview_flutter
on iOS PDF renders correctly. But when using Android PDF return a white background.
cc @bparrishMines
I haven't been able to find an API for Android WebView that displays a PDF. I believe the only options are to download the pdf and display it or use an online pdf viewer as explained in https://github.com/flutter/flutter/issues/48245#issuecomment-663892618
This navigationDelegate property is actually quite helpful. Thanks for finding it. I wonder if there is a similar one in flutter_webview_plugin, the docs don't seem to mention anything similar. We're using that one rather than flutter_webview, which is prone to crashing our Android app whenever there are complex forms, something that doesn't happen with the community version. In any event, this navigationDelegate prop has given me an idea how one can do a workaround without using any other plugin: just push another webview substituting the requested pdf url with 'https://docs.google.com/gview?embedded=true&url=${request.url}'. Could be a decent workaround for anyone with a similar use case, until webview is able to open pdf natively
@bparrishMines Thanks. do we know what happens when a user clicks on a link that points to a pdf file? Is that case handled by webview or the system ? What about zip files, etc? do we have a callback for unhandled media types?
As far as rendering a PDF from a URL is concerned, the pdf_viewer_plugin plugin seems like the right solution. https://github.com/lubritto/pdf_viewer_plugin
Any fix to this issue planned ? It is unbelievable that in iOS it can load PDFs in a web page but in Android it can not ...
Any updates on this issue?
No updates, sorry
Da: Paul V. @.> Inviato: sabato 3 dicembre 2022 08:31 A: flutter/flutter @.> Cc: albertopaganuzzi @.>; Mention @.> Oggetto: Re: [flutter/flutter] [webview_flutter] Provide callback/error for unsupported content types (e.g., PDF) (#48245)
Any updates on this issue?
— Reply to this email directly, view it on GitHub https://github.com/flutter/flutter/issues/48245#issuecomment-1336104559 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRSX3UNL4PDO2ZMIOJGZ2LWLLZMZANCNFSM4KDG35KA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AFRSX3W2QIFK4LD5EVNX3L3WLLZMZA5CNFSM4KDG35KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOJ6RVM3Y.gif Message ID: @. @.> >
--
Privacy e riservatezza: il presente messaggio, così come i relativi allegati, contengono dati ed informazioni da considerarsi strettamente riservate ed è indirizzato esclusivamente al destinatario sopra indicato, il quale è l'unico autorizzato a trattarlo in osservanza delle norme del Regolamento UE 2016/679 (RGPD). Preghiamo chiunque ricevesse questo messaggio per errore di evitare di copiarlo, divulgarlo, distribuirlo a terzi e di dare notizia al mittente dell’errato invio, distruggendone poi l'eventuale copia cartacea e la copia in formato elettronico. Grazie.
If, like in my case, the requirements is to have a shallow access to the pdf, just use
launchMode: Platform.isAndroid
? LaunchMode.externalApplication
: LaunchMode.inAppWebView,
+1
Steps to Reproduce
on iphones it works fine, but the pdf is not shown up on android emulator or physical android phone. I guess the reason is android webview doesn't support pdf? Is there a way we can add this feature?
Target Platform:android Target OS version/browser: Devices:
Logs