pdf_viewer_jk 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

pdf_viewer_jk #

A flutter plugin for viewing PDF files in mobile app (Android & iOS). based on https://github.com/CrossPT/flutter_plugin_pdf_viewer Also, upgrades made by Damodar Lohani - https://github.com/CrossPT/flutter_plugin_pdf_viewer/pull/63 are added.

Installation #

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

pdf_viewer_jk: 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)),
    );
  }

Changelog #

[1.1.0] #

  • Custom navigation color
  • Exposing ZoomableWidget from flutter_advanced_networkimage parameters (minScale, zoomSteps, maxScale,panLimit)
  • Page controller initial page setting fixed (making able to set initially loaded page)
  • Proper android cache cleanup
  • Option to pass in controller PDFViewer(document: document,controller: PageController()) that you can use to control the pageview rendering the PDF pages.
  • Option to preload all pages in memory PDFViewer(document: document,lazyLoad: false)
  • 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)
  • Removed rxdart dependency
  • Upgraded to androidX
  • Added support to optional header while loading document from url
  • Auto hide picker for 1 page documents
  • Swipe control
  • Zoom scale up to 5.0

[1.0.1] #

  • updated dependencies

[1.0.0] #

  • version number as stable.
  • added example

[0.0.4] #

  • fixed issue -- ios header files missing.

[0.0.3] #

  • fixed issue -- No podspec found.

[0.0.2] #

  • fixed few missing code parts.

[0.0.1] #

  • initial release.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _isLoading = true;
  PDFDocument document;
  String title = "Loading";

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

  loadDocument(value) async {
    setState(() {
      _isLoading = true;
      title = "Loading";
    });
    if (value == 1) {
      document = await PDFDocument.fromURL(
          "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
    } else {
      document = await PDFDocument.fromAsset('assets/sample.pdf');
    }
    setState(() {
      title = (value == 1) ? "Loaded From Url" : "Loaded From Assets";
      _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 URL'),
                    onTap: () {
                      loadDocument(1);
                    },
                  ),
                  ListTile(
                    title: Text('Load from Assets'),
                    onTap: () {
                      loadDocument(0);
                    },
                  ),
                ],
              ),
            ),
            appBar: AppBar(
              title: Text(title),
            ),
            body: Center(
                child: _isLoading
                    ? Center(child: CircularProgressIndicator())
                    : PDFViewer(
                        document: document,
                        zoomSteps: 1,
                        //preload all pages
                        // lazyLoad: false,
                        // 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:
  pdf_viewer_jk: ^1.1.0

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:pdf_viewer_jk/pdf_viewer_jk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Maintenance suggestions

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

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.2.2 1.4.0
numberpicker ^1.2.0 1.2.0
path_provider ^1.6.8 1.6.10
Transitive dependencies
charcode 1.1.3
clock 1.0.1
collection 1.14.12
convert 2.1.1
crypto 2.1.5
file 5.1.0
flutter_svg 0.17.4
http 0.12.1
http_parser 3.1.4
infinite_listview 1.0.1+1
intl 0.16.1
meta 1.1.8
path 1.7.0
path_drawing 0.4.1
path_parsing 0.1.4
path_provider_linux 0.0.1+1
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0
petitparser 3.0.4
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
rxdart 0.24.1
sky_engine 0.0.99
source_span 1.7.0
sqflite 1.3.0+2 1.3.1-dev.1
sqflite_common 1.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
xdg_directories 0.1.0
xml 3.7.0 4.2.0
Dev dependencies
flutter_test