Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open and PDF or word document in the [Flutter]

Question is simple, I would like to open any pdf or doc file via default App with using Flutter.

Think a Raised button that related my pdf asset, when user press it, pdf will be opened via Acrobat reader or etc. I don't want to use any web_view for it.

is it supported in Flutter?

like image 357
Weud Avatar asked Mar 12 '18 11:03

Weud


People also ask

How do I open a PDF from URL in flutter?

The Syncfusion Flutter PDF Viewer widget provides the support to load a PDF document from Asset, Network, File, and Memory. The SfPdfViewer.network is used to load a PDF document from a URL, which creates a widget that displays the PDF document obtained from the provided URL.


2 Answers

You can do this by opening google docs in a web browser :

In pubspec.yaml you need :

url_launcher: ^0.4.2+5 

Includes :

import 'package:flutter/src/gestures/tap.dart'; import 'package:url_launcher/url_launcher.dart'; 

Code snippet :

new RichText(   text: new LinkTextSpan(       url: 'http://docs.google.com/viewer?url=http://www.pdf995.com/samples/pdf.pdf',       text: 'Show My Pdf'), ), 

LinkTextSpan class :

class LinkTextSpan extends TextSpan {   LinkTextSpan({TextStyle style, String url, String text})       : super(       style: style,       text: text ?? url,       recognizer: new TapGestureRecognizer()         ..onTap = () {           launch(url);         }); } 
like image 43
Rockvole Avatar answered Sep 23 '22 18:09

Rockvole


A good and simple approach to this is the open_file package which lets you open a file with the given path. It supports numerous different file types:

import 'package:open_file/open_file.dart';  OpenFile.open("/sdcard/example.pdf"); 
like image 157
Bostrot Avatar answered Sep 22 '22 18:09

Bostrot