advance_pdf_viewer 1.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • new82

advance_pdf_viewer #

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

Pub Package

Installation #

Add advance_pdf_viewer as a dependency in your pubspec.yaml file.

advance_pdf_viewer: any

Android #

No permissions required. Uses application cache directory.

iOS #

No permissions required.

How-to: #

Load PDF

// Load from assets
PDFDocument doc = await PDFDocument.fromAsset('assets/test.pdf');
 
// Load from URL
PDFDocument doc = await PDFDocument.fromURL('http://www.africau.edu/images/default/sample.pdf');

// Load from file
File file  = File('...');
PDFDocument doc = await PDFDocument.fromFile(file);

Load pages

// Load specific page
PDFPage pageOne = await doc.get(page: _number);

Pre-built viewer

Use the pre-built PDF Viewer

@override
  Widget build(BuildContext context) {
    Scaffold(
        appBar: AppBar(
          title: Text('Example'),
        ),
        body: Center(
        child: _isLoading
            ? Center(child: CircularProgressIndicator())
            : PDFViewer(document: document)),
    );
  }

This code produces the following view:

Demo Screenshot 1

TODO #

  • Allow password-protected files
  • Refactor PDFDocument.getAll() method
  • Increase page resolution
  • Add swipe to change page

Third-party packages used

NameDescription
path_providerA Flutter plugin for finding commonly used locations on the filesystem. Supports iOS and Android.
flutter_cache_managerA CacheManager to download and cache files in the cache directory of the app. Various settings on how long to keep a file can be changed.
numberpickerNumberPicker is a custom widget designed for choosing an integer or decimal number by scrolling spinners.
flutter_advanced_networkimageAn advanced image provider provides caching and retrying for flutter app. Now with zoomable widget and transition to image widget.

Changelog #

1.1.6 #

1.1.5 #

  • Page controller initial page setting fixed (making able to set initially loaded page)

1.1.4 #

  • Proper android cache cleanup
  • iOS build fix

1.1.3 #

  • Option to pass in controller PDFViewer(document: document,controller: PageController()) that you can use to control the pageview rendering the PDF pages.

1.1.2 #

  • Option to preload all pages in memory PDFViewer(document: document,lazyLoad: false)

1.1.1 #

  • Option to disable swipe navigation PDFViewer(document: document,scrollDirection: Aixs.vertical)
  • Option to change scroll axis to vertical or horizontal PDFViewer(document: document,scrollDirection: Aixs.vertical)

1.1.0 #

  • Removed rxdart dependency
  • Upgraded to androidX
  • Added support to optional header while loading document from url
  • Auto hide picker for 1 page documents

1.0.1 #

  • Swipe control
  • Zoom scale up to 5.0

1.0.0 #

  • First upgraded version after fork
  • Cool new customization features

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isLoading = true;
  PDFDocument document;

  @override
  void initState() {
    super.initState();
    loadDocument();
  }

  loadDocument() async {
    document = await PDFDocument.fromAsset('assets/sample.pdf');

    setState(() => _isLoading = false);
  }

  changePDF(value) async {
    setState(() => _isLoading = true);
    if (value == 1) {
      document = await PDFDocument.fromAsset('assets/sample2.pdf');
    } else if (value == 2) {
      document = await PDFDocument.fromURL(
          "http://conorlastowka.com/book/CitationNeededBook-Sample.pdf");
    } else {
      document = await PDFDocument.fromAsset('assets/sample.pdf');
    }
    setState(() => _isLoading = false);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        drawer: Drawer(
          child: Column(
            children: <Widget>[
              SizedBox(height: 36),
              ListTile(
                title: Text('Load from Assets'),
                onTap: () {
                  changePDF(1);
                },
              ),
              ListTile(
                title: Text('Load from URL'),
                onTap: () {
                  changePDF(2);
                },
              ),
              ListTile(
                title: Text('Restore default'),
                onTap: () {
                  changePDF(3);
                },
              ),
            ],
          ),
        ),
        appBar: AppBar(
          title: const Text('FlutterPluginPDFViewer'),
        ),
        body: Center(
          child: _isLoading
              ? Center(child: CircularProgressIndicator())
              : PDFViewer(
                  document: document,
                  zoomSteps: 1,
                  //uncomment below line to preload all pages
                  // lazyLoad: false,
                  // uncomment below line to scroll vertically
                  // scrollDirection: Axis.vertical,

                  //uncomment below code to replace bottom navigation with your own
                  /* navigationBuilder:
                      (context, page, totalPages, jumpToPage, animateToPage) {
                    return ButtonBar(
                      alignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        IconButton(
                          icon: Icon(Icons.first_page),
                          onPressed: () {
                            jumpToPage()(page: 0);
                          },
                        ),
                        IconButton(
                          icon: Icon(Icons.arrow_back),
                          onPressed: () {
                            animateToPage(page: page - 2);
                          },
                        ),
                        IconButton(
                          icon: Icon(Icons.arrow_forward),
                          onPressed: () {
                            animateToPage(page: page);
                          },
                        ),
                        IconButton(
                          icon: Icon(Icons.last_page),
                          onPressed: () {
                            jumpToPage(page: totalPages - 1);
                          },
                        ),
                      ],
                    );
                  }, */
                ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  advance_pdf_viewer: ^1.1.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_advanced_networkimage ^0.7.0 0.7.0
flutter_cache_manager ^1.1.3 1.1.3
numberpicker ^1.2.0 1.2.0
path_provider ^1.6.5 1.6.5
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
flutter_svg 0.17.3+1
http 0.12.0+4
http_parser 3.1.4
infinite_listview 1.0.1+1
meta 1.1.8
path 1.6.4
path_drawing 0.4.1
path_parsing 0.1.4
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
pedantic 1.9.0
petitparser 3.0.2
platform 2.2.1
plugin_platform_interface 1.0.2
sky_engine 0.0.99
source_span 1.7.0
sqflite 1.3.0
sqflite_common 1.0.0+1
string_scanner 1.0.5
synchronized 2.2.0
term_glyph 1.1.0
typed_data 1.1.6
uuid 2.0.4
vector_math 2.0.8
xml 3.7.0 4.1.0