Enhanced PDF view for Flutter.

Overview

flutter_cached_pdfview

Awesome Flutter

Pub Version GitHub repo size issues-raw license last-commit stars Dart CI


A package to show Native PDF View for iOS and Android, support Open from a different resource like Path, Asset or Url and Cache it.

Support = [ Android , IOS and WEB(soon) ];

  • Open Pdf From Path(local file)
  • Open Pdf From Asset
  • Open Pdf From URl and Cache it
  • Display horizontally or vertically
  • Drag and zoom
  • Double tap for zoom
  • Support password protected pdf
  • Jump to a specific page in the pdf

Setup

iOS

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

iOS (only support> 11.0) you need to add this line in your ios/Podfile

platform :ios, '11.0'

ready-made in the Example

Import it

Now in your Dart code, you can use:

import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';

Options

Name Android iOS Default
defaultPage 0
onViewCreated null
onRender null
onPageChanged null
onError null
onPageError null
onLinkHandle null
gestureRecognizers null
filePath
fitPolicy FitPolicy.WIDTH
enableSwipe true
swipeHorizontal false
password null
nightMode false
autoSpacing true
pageFling true
pageSnap true
preventLinkNavigation false

Controller Options

Name Description Parameters Return
getPageCount Get total page count - Future<int>
getCurrentPage Get current page - Future<int>
setPage Go to/Set page int page Future<bool>

Example

from Asset

       PDF(
        enableSwipe: true,
        swipeHorizontal: true,
        autoSpacing: false,
        pageFling: false,
        onError: (error) {
          print(error.toString());
        },
        onPageError: (page, error) {
          print('$page: ${error.toString()}');
        },
        onPageChanged: (int page, int total) {
          print('page change: $page/$total');
        },
      ).fromAsset('assets/pdf/file-example.pdf'),

cached From Url

      PDF(
        swipeHorizontal: true,
      ).cachedFromUrl('http://africau.edu/images/default/sample.pdf'),

with placeholder until pdfFile download and errorWidget if there are problem

      PDF().cachedFromUrl(
             'http://africau.edu/images/default/sample.pdf',
             placeholder: (progress) => Center(child: Text('$progress %')),
             errorWidget: (error) => Center(child: Text(error.toString())),
           )

For production usage

If you use proguard, you should include this line [ready-made in the Example].

-keep class com.shockwave.**

Dependencies

Flutter

flutter_pdfview

flutter_cache_manager

Android (only support >= api 20)

AndroidPdfViewer

iOS (only support> 11.0)

PDFKit

Video

IOS

WEB

Support

Buy Me A Coffee

Donate with PayPal button
buy me a coffee by PayPal

Developer

Comments
  • Blank PDF on Android --release

    Blank PDF on Android --release

    When running Flutter in --release mode, the pdf is blank page. This does not happen in iOS or in Android debug mode.

    To Reproduce

    PDF(swipeHorizontal: false).cachedFromUrl('https://firebasestorage.googleapis.com/v0/b/[...]')

    Smartphone (please complete the following information):

    • Device: [Pixel 1]
    • Version [Android 10]

    Additional context Dart 2.11.0 flutter_cached_pdfview: ^0.3.5

    bug 
    opened by dgriff24 6
  • Old path_provider version causes import failure

    Old path_provider version causes import failure

    Please, update dependencies, because right now I can't integrate the library: Because ess_front depends on flutter_cached_pdfview ^0.3.5 which depends on path_provider ^1.6.27, path_provider ^1.6.27 is required. So, because ess_front depends on path_provider ^2.0.1, version solving failed. pub get failed (1; So, because ess_front depends on path_provider ^2.0.1, version solving failed.)

    I can't lower path_provider, because file_picker uses a newer version.

    bug 
    opened by wellbranding 5
  • Massive app size increase after install this plugin

    Massive app size increase after install this plugin

    Describe the bug Before installing the plugin, my app was 26.3 Mb and After I install the ^0.2.8 version of this plugin the app size increased up to 44.6Mb on android

    To Reproduce Steps to reproduce the behavior: Install the plugin and run flutter build apk --release

    Expected behavior There is at least an 18Mb gap between two builds. Is the plugin has this much size?

    Desktop (please complete the following information):

    • OS: Widows
    • Version: 10

    Smartphone (please complete the following information):

    • Device: Nexus 5x Emulator
    • OS: Android
    • Version 9.0
    bug 
    opened by SaliBhdr 5
  • Error while running assembleDebug

    Error while running assembleDebug

    Describe the bug When I am trying to run my app on any device it's showing the following error `Execution failed for task ':app:checkDebugAarMetadata'.

    Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.github.barteksc:android-pdf-viewer:3.2.0-beta.1. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/github/barteksc/android-pdf-viewer/3.2.0-beta.1/android-pdf-viewer-3.2.0-beta.1.pom - https://repo.maven.apache.org/maven2/com/github/barteksc/android-pdf-viewer/3.2.0-beta.1/android-pdf-viewer-3.2.0-beta.1.pom - https://storage.googleapis.com/download.flutter.io/com/github/barteksc/android-pdf-viewer/3.2.0-beta.1/android-pdf-viewer-3.2.0-beta.1.pom Required by: project :app > project :flutter_pdfview`

    This problem solves This problem solves after adding jcenter() in allprojects->repositories in build.gradle in android folder But I don't understand why this error occures at all

    bug 
    opened by rushikeshnarwade 4
  • Unable to Open the Shared File of Google drive

    Unable to Open the Shared File of Google drive

    Describe the bug I have create your sample project clone and then after I tried to view the PDF This One : https://drive.google.com/file/d/1GkgKDPjtnv-WXd8k0Jc1y6su20RFnZy6/view?usp=sharing I was unable to View.

    Is there any way to do this : So please tell me PDF( swipeHorizontal: true, ).cachedFromUrl( 'https://drive.google.com/file/d/1GkgKDPjtnv-WXd8k0Jc1y6su20RFnZy6/view?usp=sharing'), )

    Desktop (please complete the following information):

    • Using in Android 10
    bug 
    opened by sumitzartek 4
  • Getting page count return 0

    Getting page count return 0

    i this code that i used in our application i get zero for getting page count

    import 'dart:async';
    
    import 'package:flutter/material.dart';
    import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
    import 'package:velocity_x/velocity_x.dart';
    
    class ShowPdfFromUrl extends StatefulWidget {
      final String pdfUrl;
      final String productName;
    
      ShowPdfFromUrl({@required this.pdfUrl, @required this.productName});
    
      @override
      _ShowPdfFromUrlState createState() => _ShowPdfFromUrlState();
    }
    
    class _ShowPdfFromUrlState extends State<ShowPdfFromUrl> {
      final Completer<PDFViewController> _pdfViewController = Completer<PDFViewController>();
      final ValueNotifier<int> _pageCount = ValueNotifier<int>(0);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
              '${widget.productName}',
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
            ),
          ),
          body: Stack(
            children: [
              PDF(
                onViewCreated: (PDFViewController pdfViewController) async {
                  _pdfViewController.complete(pdfViewController);
                  _pageCount.value = await pdfViewController.getPageCount();
                },
              ).cachedFromUrl(
                '${widget.pdfUrl}',
                placeholder: (progress) => Center(child: Text('Yükleniyor $progress % ...')),
                errorWidget: (error) {
                  return Center(
                      child: Container(
                        width: context.screenWidth,
                        height: context.screenHeight,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Text('PDF hatası indiriliyor'),
                            Padding(
                              padding: const EdgeInsets.only(top: 16.0),
                              child: OutlineButton(
                                onPressed: () {
                                  setState(() {});
                                },
                                child: Text('lütfen tekrar deneyin'),
                              ),
                            ),
                          ],
                        ),
                      ));
                },
              ),
    
              Positioned(
                top: 8.0,
                left: 8.0,
                child: ValueListenableBuilder(
                  valueListenable: _pageCount,
                  builder: (_,value,__){
                    return Container(
                      padding: EdgeInsets.all(8.0),
                      color: Colors.black,
                      child: Text('($value)',style: TextStyle(
                        color: Colors.white,
                      ),),
                    );
                  },
                ),
              ),
            ],
          ),
        );
      }
    }
    
    bug 
    opened by pishguy 4
  • No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String)

    No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String)

    Describe the bug When trying to get pdf from the network, the pdf gets loaded to 100% but only a white screen is shown instead of pdf itself. I can see this error in the log.

    To Reproduce I am using the code to fetch pdf from the network from the example itself.

    bug 
    opened by logblythe 3
  • How to make a widget test of this component?

    How to make a widget test of this component?

    I know the component is on the screen, because I put a key on your ancestor and verified that the ancestor was found

    final PDFWidget = find.byType(PDF); expect(PDFWidget, findsOneWidget);

    return _WidgetTypeFinder:<zero widgets with type "PDF" (ignoring offstage widgets)

    bug 
    opened by mdmota 3
  • filePath - does it get the cached file path?

    filePath - does it get the cached file path?

    I'm using cacheFromURL, and I want to get the cached filePath in order to use it with "Share".

    I'm missing something, can't find the filePath property.

    Please help.

    opened by yakeer 3
  • Error in Android System, when I test in emulator or real device.

    Error in Android System, when I test in emulator or real device.

    I am to test in android system. When I test the app on the emulator or real device, the view does not show the pdf.

    Appears this error

    D/com.shockwave.pdfium.PdfiumCore( 3943): Starting PdfiumAndroid 1.9.0 E/MethodChannel#flutter/platform_views( 3943): Failed to handle method call E/MethodChannel#flutter/platform_views( 3943): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference E/MethodChannel#flutter/platform_views( 3943): at io.endigo.plugins.pdfviewflutter.FlutterPDFView.getBoolean(FlutterPDFView.java:171) E/MethodChannel#flutter/platform_views( 3943): at io.endigo.plugins.pdfviewflutter.FlutterPDFView.(FlutterPDFView.java:33) E/MethodChannel#flutter/platform_views( 3943): at io.endigo.plugins.pdfviewflutter.PDFViewFactory.create(PDFViewFactory.java:22) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:179) E/MethodChannel#flutter/platform_views( 3943): at android.app.Dialog.dispatchOnCreate(Dialog.java:389) E/MethodChannel#flutter/platform_views( 3943): at android.app.Dialog.show(Dialog.java:293) E/MethodChannel#flutter/platform_views( 3943): at android.app.Presentation.show(Presentation.java:235) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:94) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:47) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:112) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:95) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#flutter/platform_views( 3943): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631) E/MethodChannel#flutter/platform_views( 3943): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#flutter/platform_views( 3943): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#flutter/platform_views( 3943): at android.os.Looper.loop(Looper.java:136) E/MethodChannel#flutter/platform_views( 3943): at android.app.ActivityThread.main(ActivityThread.java:6077) E/MethodChannel#flutter/platform_views( 3943): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views( 3943): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) E/MethodChannel#flutter/platform_views( 3943): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) E/flutter ( 3943): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference, null) E/flutter ( 3943): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter ( 3943): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18) E/flutter ( 3943): E/flutter ( 3943): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12) E/flutter ( 3943): #3 AndroidViewController._create (package:flutter/src/services/platform_views.dart:633:54) E/flutter ( 3943): #4 AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:550:14) E/flutter ( 3943): #5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:175:29) E/flutter ( 3943): #6 RenderAndroidView.performResize (package:flutter/src/rendering/platform_view.dart:156:5) E/flutter ( 3943): #7 RenderObject.layout (package:flutter/src/rendering/object.dart:1746:9) E/flutter ( 3943): #8 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13) E/flutter ( 3943): #9 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) E/flutter ( 3943): #10 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:11) E/flutter ( 3943): #11 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:484:7) E/flutter ( 3943): #12 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7) E/flutter ( 3943): #13 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:399:14) E/flutter ( 3943): #14 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1630:7) E/flutter ( 3943): #15 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:887:18) E/flutter ( 3943): #16 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:402:19) E/flutter ( 3943): #17 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:13) E/flutter ( 3943): #18 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5) E/flutter ( 3943): #19 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15) E/flutter ( 3943): #20 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9) E/flutter ( 3943): #21 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:968:5) E/flutter ( 3943): #22 _rootRun (dart:async/zone.dart:1184:13) E/flutter ( 3943): #23 _CustomZone.run (dart:async/zone.dart:1077:19) E/flutter ( 3943): #24 _CustomZone.runGuarded (dart:async/zone.dart:979:7) E/flutter ( 3943): #25 _invoke (dart:ui/hooks.dart:261:10) E/flutter ( 3943): #26 _drawFrame (dart:ui/hooks.dart:219:3) E/flutter ( 3943): D/ ( 3943): HostConnection::get() New Host Connection established 0x9aa91c80, tid 3955 D/ ( 3943): HostConnection::get() New Host Connection established 0x82734a80, tid 4021 D/ ( 3943): HostConnection::get() New Host Connection established 0x9aa91c00, tid 3952

    opened by Romavic 3
  • Please review the class DownloadIndicator.

    Please review the class DownloadIndicator.

    In the DownloadIndicator class, if Text ('Downloading ...') appears, you should have the programmer's option to write whatever he wants in place of "Downloading".

    So Text ('Downloading ...'), it should just be a Widget, which for anyone who wants to use the library should, put whatever he wants, while downloading the pdf ...

    It may be the case that in place of Text ('Downloading ...'), I want to put a Gif ... or something else ...

    Do you understand what I want?

    opened by Romavic 3
  • Thanks for this great library. 🙏❤️

    Thanks for this great library. 🙏❤️

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    opened by muhammadkarbalaee 0
  • Handshake Error

    Handshake Error

    Describe the bug I got some error when i using https on url then showing error Handshake Error in Client (OS Error: CERTIFICATE_VERIFY_FAILED)..

    Screenshots WhatsApp Image 2022-08-29 at 9 36 34 AM

    Smartphone (please complete the following information):

    • Device: Samsung Galaxy A50s
    • OS: Android 11
    bug 
    opened by taftazaniadi 0
  • Changing PDF background color

    Changing PDF background color

    Is there a way of changing the PDF's background color (instead of the default grey color)? And is there a way to snap the PDF to the top part of the widget, and avoid the vast "dead area" around the document?

    opened by Yahllil 1
  • Add Android set up steps

    Add Android set up steps

    The version 0.4.1 uses a dependency that isn't on the default repositories for a new Flutter project. The way to fix this is by adding the jcenter repo to the repo list in the build.gradle file.

    opened by ewilliams-zoot 1
Owner
Abdelrahman Saed
Software developer with professional experience focused in Flutter, previous experience with Android native(java), and familiar with backend using NodeJs.
Abdelrahman Saed
Flutter list view - An unofficial list view for flutter

Flutter List View I don't like official list view. There are some features don't

null 24 Dec 15, 2022
Grid-View-App - Grid View App For Flutter

grid_view_app practice purpose flutter application Getting Started This project

Md Tarequl Islam 4 Jun 9, 2022
Swipeable button view - Create Ripple Animated Pages With Swipeable Button View

swipeable_button_view You can create ripple animated pages with swipeable_button

cemreonur 3 Apr 22, 2022
-UNDER DEVELOPMENT- a project built demonstrating model view view model architecture

mvvm_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Atuoha Anthony 4 Nov 28, 2022
Bac-App-Flutter - Flutter application where you can read PDF locally or by internet and is saved

Bac App - Flutter Flutter application where you can read PDF locally or by inter

Chakib Ammar Aouchiche 3 Jun 7, 2022
A flutter plugin for viewing PDF files in mobile app (Android & iOS)

PDF Viewer (JK) A flutter plugin for viewing PDF files in mobile app (Android & iOS) Pub.dev https://pub.dev/packages/pdf_viewer_jk Github ht

Jawad 8 Sep 30, 2021
A flutter plugin for handling PDF files

advance_pdf_viewer A flutter plugin for handling PDF files. Works on both Android & iOS. Originally forked from (https://github.com/CrossPT/flutter_pl

Abeer Iqbal 0 Dec 3, 2021
Pdf creation module for dart/flutter

Pdf for Dart and Flutter This set of plugins allows Flutter apps to generate and print pdf files to the device printer. This plugin works for iOS and

David PHAM-VAN 954 Jan 3, 2023
Flutter agenda - Flutter Agenda View Package (pub.dev)

Flutter Agenda View Agenda Widget Package for Flutter Features Image Video Recor

Iliyass Zamouri 3 Apr 15, 2022
A periodic table app with 3D view of the elements built using flutter.

A flutter app which takes you on a 3d visualisation of the 118 elements of the periodic table. promo.mp4 Tech Stack Deployed using How it all began It

Shanwill Pinto 48 Nov 16, 2022
Flutter Split View and Drawer Navigation example

Flutter Split View and Drawer Navigation example This repo contains the source code for this tutorial: Responsive layouts in Flutter: Split View and D

Andrea Bizzotto 32 Nov 17, 2022
Flutter Insert, Update, Delete and add form view dynamic

salesapp Insert, Update, Delete and form view add dynamic. Getting Started This project is a starting point for a Flutter application. A few resources

null 1 Dec 22, 2021
A flutter list view which can drag & move item to change order.

draggable_flutter_list A flutter list view which can drag & move item to change order. some codes come from flutter_list_drag_and_drop fix flutter_lis

刘彦博 40 Sep 22, 2022
Search and view popular Youtube videos with Youtube API in Flutter App

getx_bottom_nav_sample The sample of AnimatedBottomNavBar with GetX 주요 Package 설명 1.url_launcher url_launcher pub.dev flutter 에서 인앱, 외부 브라우저로 연길 시켜 주는

Jacob Ko 1 Dec 25, 2021
A Flutter package for paginating a list view

paging A Flutter package for paginating a list view Installation Add this to your package's pubspec.yaml file dependencies: ... paging: ^latest.ve

Joshua Matta 36 Dec 12, 2022
A Food App using Flutter & Firebase to post and view food blogs along with their recipes.

A Food App using Flutter ?? & Firebase ?? About the App ?? FoodLab is a App to post and view food blogs along with their recipes if you want ?? ! Logi

Shivani Singh 170 Dec 24, 2022
Embeddable unity game engine view for Flutter.

flutter_unity_widget Flutter unity 3D widget for embedding unity in flutter. Now you can make awesome gamified features of your app in Unity and get i

Rex Raphael 1.7k Jan 8, 2023
A WEB 3 Exploration Flutter APP that let you view NFTS

It is simply a WEB 3 Exploration APP that let you view NFTS (News about web 3 ar

null 11 Nov 22, 2022
A section list view for flutter

Section view Features Show with select view Alphabet support Refresh support Scr

null 6 Nov 6, 2022