PDF with Flutter

PDF with Flutter

In Flutter there are various features that make you app rich in functionality and provide ease to the user to do stuff within the app and get better user experience and being a service provider it is also necessary for developers. These small but important functionalities like picking up contacts from the contact list, images, and videos from the gallery, opening maps, automatic OTP recognition, are some important features that make any app comfortable to use and in this article, we are going to explain a simple but important functionality named pdf viewer.

In Flutter there are various features that make you app rich in functionality and provide ease to the user to do stuff within the app and get better user experience and being a service provider it is also necessary for developers.

These small but important functionalities like picking up contacts from the contact list, images, and videos from the gallery, opening maps, automatic OTP recognition, are some important features that make any app comfortable to use and in this article, we are going to explain a simple but important functionality named pdf viewer.

There are different packages which you can use to open a pdf in your app some are a bit complicated and some are easy to implement and here I am going to explain one of the easiest ways to use it.

Implementation:

For this, you just need to add the dependencies in your pubspec.yaml file

pdf_flutter: 
file_picker: 

After adding dependencies you have different options to use it, It depends, from where you want to access your pdf like from assets, from your phone storage, or by any link(from server).

So let's see all methods of accessing pdf from different locations

From asset Folder

From the asset folder, you can easily access your pdf file if you have mentioned it in your pubspec.yaml file. Here you are also required to mention placeholder in case of unavailability of resources.

PDF.assets(
  "assets/demo.pdf",
  height: MediaQuery.of(context).size.height,
  width: MediaQuery.of(context).size.width,
  placeHolder: Image.asset("assets/images/pdf.png",
      height: 200, width: 100),
),

From Phone Storage

Some times you need to access pdf from your phone especially in the case when you are posting any document in the server. The only thing which is different from the above code is PDF.file and but as we are picking it up from phone so we need to add the dependency of *file_picker *then we need to create an instance of the file picker

File localFile;

and then it will allow you to access your phone directory

PDF.file(
  localFile,
  height: MediaQuery.of(context).size.height,
  width: MediaQuery.of(context).size.width,
  placeHolder: Image.asset(
    "assets/images/pdf.png",
height: 200, width: 100
  ),
),

pdf mobile flutter mobile-app-development pdf-viewer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Hire Mobile App Developers in USA

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.

Top Mobile App Developers & Leading App Development Companies in UK

Profusely examined top Mobile App Development companies in UK with ratings & reviews to help find the best Mobile App Development solution providers.

Top Mobile App Development Company in Texas

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.

Top Mobile App Development Company in Pennsylvania

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.