flutter_pdf_viewer 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 87

flutter pdf viewer

Android Only!

A native Pdf viewer for flutter, built on AndroidPdfViewer, which is based on PdfiumAndroid

Features

  • Night Mode
  • Scroll Bar
  • Horizontal swipe
  • Pinch to zoom
  • Download PDF from URL

Security

  • Features fast, in-memory native XOR - decryption of files.
  • Password protected pdf.
  • Download and display PDF from URL without ever touching the disk!

Drawbacks

  • Inline Pdf Viewing is not supported. ( A new activity is opened ). See #1.

Install

To use this plugin, follow the installation instructions.

pub package

License: MIT

Example

Put test.pdf at assets/test.pdf

# pubspec.yaml

flutter:
    ...

    assets:
        - assets/test.pdf
// main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: RaisedButton(
            onPressed: () => FlutterPdfViewer.loadAsset('assets/test.pdf'),
            child: Text('OPEN'),
          ),
        ),
      ),
    );
  }
}

Alternatively,

$ git clone https://github.com/pycampers/flutter_pdf_viewer.git
$ cd flutter_pdf_viewer/example
$ flutter run

Preview

API

import 'package:flutter_pdf_viewer/flutter_pdf_viewer.dart';



/// Load Pdf from file path.
/// (Uses the native file URI parser)
Future<void> FlutterPdfViewer.loadFilePath(
    String filePath, {
    String password,
    bool nightMode,
    String xorDecryptKey,
    bool swipeHorizontal,
})


/// Load Pdf from raw bytes.
Future<void> FlutterPdfViewer.loadBytes(
    Uint8List pdfBytes, {
    String password,
    bool nightMode,
    String xorDecryptKey,
    bool swipeHorizontal,
})


/// Load Pdf from Flutter's asset folder
Future<void> FlutterPdfViewer.loadAsset(
    String assetPath, {
    String password,
    bool nightMode,
    String xorDecryptKey,
    bool swipeHorizontal,
})


// Download from url as a file (cached to disk)
Future<String> FlutterPdfViewer.downloadAsFile(String url, {bool cache: true})


// Download from file as bytes (in-memory)
Future<Uint8List> FlutterPdfViewer.downloadAsBytes(String url)

Thanks


<a href="https://www.buymeacoffee.com/u75YezVri" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/black_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

🐍🏕️

0.0.1

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:typed_data';

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: ListView(
            children: [
              LoadFromAssetButton(),
              LoadUrlAsFile(),
              LoadUrlAsBytes(),
              LoadHorizontalPdf()
            ],
          ),
        ),
      ),
    );
  }
}

class LoadFromAssetButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () {
        FlutterPdfViewer.loadAsset('assets/test.pdf');
      },
      child: Text('open from assets'),
    );
  }
}

class LoadUrlAsFile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () async {
        Scaffold.of(context).showSnackBar(
          SnackBar(
            content: Text('Downloading...'),
            duration: Duration(days: 24),
          ),
        );

        String filePath = await FlutterPdfViewer.downloadAsFile(
          'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf',
        );

        print("filePath: '$filePath'");

        Scaffold.of(context).hideCurrentSnackBar();

        FlutterPdfViewer.loadFilePath(filePath);
      },
      child: Text('download + load as file (cached)'),
    );
  }
}

class LoadUrlAsBytes extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () async {
        Scaffold.of(context).showSnackBar(
          SnackBar(
            content: Text('Downloading...'),
            duration: Duration(days: 24),
          ),
        );

        Uint8List bytes = await FlutterPdfViewer.downloadAsBytes(
          'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf',
        );

        Scaffold.of(context).hideCurrentSnackBar();

        FlutterPdfViewer.loadBytes(bytes);
      },
      child: Text('download + load as bytes (not cached)'),
    );
  }
}

class LoadHorizontalPdf extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () {
        FlutterPdfViewer.loadAsset('assets/test.pdf', swipeHorizontal: true);
      },
      child: Text('open horizontal pdf'),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_pdf_viewer: ^0.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_pdf_viewer/flutter_pdf_viewer.dart';
  
Version Uploaded Documentation Archive
0.0.4 Oct 9, 2018 Go to the documentation of flutter_pdf_viewer 0.0.4 Download flutter_pdf_viewer 0.0.4 archive
0.0.3 Aug 21, 2018 Go to the documentation of flutter_pdf_viewer 0.0.3 Download flutter_pdf_viewer 0.0.3 archive
0.0.2 Jul 16, 2018 Go to the documentation of flutter_pdf_viewer 0.0.2 Download flutter_pdf_viewer 0.0.2 archive
0.0.1 Jul 16, 2018 Go to the documentation of flutter_pdf_viewer 0.0.1 Download flutter_pdf_viewer 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
86
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/downloader.dart.

Run flutter format to format lib/downloader.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
crypto ^2.0.6 2.0.6
flutter 0.0.0
http ^0.12.0 0.12.0
path_provider ^0.4.1 0.4.1
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.0.2
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8