Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open the pdf document inside web view using flutter

Tags:

flutter

I am creating an app using flutter. I am struggling to open the Portable Document Format inside the web view using flutter. Please help to resolve this

body: SafeArea( child: WebView(
initialUrl: pdf filePath, javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (WebViewController webViewController) { _webViewController = webViewController; _webViewController.clearCache(); _webViewController.reload(); }, ), ),

my code

    SafeArea( child: WebView( initialUrl: filePath, javascriptMode: 
JavascriptMode.unrestricted, 
onWebViewCreated: (WebViewController webViewController) { _webViewController = webViewController; 
_webViewController.clearCache(); 
_webViewController.reload(); }, ), ),
like image 566
arul Avatar asked Mar 15 '26 18:03

arul


1 Answers

I was facing the same issue before and I used this method to solve that. In the initialUrl you can check if the url is a pdf link and use google doc to open it.

initialUrl:  widget.link!.indexOf('.pdf') != -1 ? 'https://docs.google.com/gview? 
                    embedded=true&url=${widget.link}'
                    : widget.link!
like image 152
Dare Oloruntoba Avatar answered Mar 17 '26 08:03

Dare Oloruntoba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!