native_pdf_renderer 1.4.1

PDF Renderer #

Flutter Plugin to render PDF pages as images on both Android 5+ and iOS devices.

Implementation of support for andgpoid 4.4 in plans #

Getting Started #

In your flutter project add the dependency:

pub package

dependencies:
  ...
  native_pdf_renderer: any

For help getting started with Flutter, view the online documentation.

Usage example #

Read more

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:native_pdf_renderer/native_pdf_renderer.dart';

void main() async {
  try {
    final document = await PDFDocument.openAsset('assets/sample.pdf');
    final page = await document.getPage(1);
    final pageImage = await page.render(width: page.width, height: page.height);
    await page.close();
    runApp(
      MaterialApp(
        home: Scaffold(
          body: Center(
            child: Image(
              image: MemoryImage(pageImage.bytes),
            ),
          ),
        ),
        color: Colors.white,
      )
    );
  } on PlatformException catch (error) {
    print(error);
  }
}

Rendering PDF files on Android devices #

Use the provided widget PdfRenderer in order to render a PDF file. This plugin uses the Android native PdfRenderer to render the pages of PDF files and provides a widget called PdfRenderer to display the PDF page you like.

1.4.1 #

  • Resolve supports Flutter v1.7

1.4.0+1 #

  • Hotfix

1.4.0 #

  • Now format and backgroundColor options for image rendering works on IOS.

1.3.0+1 #

  • Hotfix

1.3.0 #

  • Added format and backgroundColor options for image rendering. Attention: it feature works only on Android platform!
  • Added dart linter
  • Refactoring existing code

1.2.3 #

  • Scale fix on IOS

1.2.2 #

  • Upgrade to Swift 5

1.2.1 #

  • Fix IOS build error

1.2.0 #

  • Optimized UI freezes on android platform

1.1.2 #

  • Update readme

1.1.1 #

  • Fix compilation error on pure android Java projects (#1)

1.1.0 #

  • Transferred sources to src directory
  • Removed dispose method from PDFDocument class (Replaced by close method)
  • Added more comments in code

1.0.1 #

  • Fixed support capability dart v2.0 (non 2.1) by add import dart:core in files with use Future

1.0.0 #

  • Initial release

example/README.md

Example of usage native_pdf_renderer

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:native_pdf_renderer/native_pdf_renderer.dart';

void main() async {
  try {
    final document = await PDFDocument.openAsset('assets/sample.pdf');

    // Or open from data:
    // final document = await PDFDocument.openData(<Uint8List>);

    // Or open from file path:
    // final document = await PDFDocument.openFile('absolute/path/to/file');


    final page = await document.getPage(1); // Not index! Page number starts from 1

    final pageImage = await page.render(width: page.width, height: page.height);
    // You can increase image quality:
    // final pageImage = await page.render(width: page.width * 3, height: page.height * 3);

    // Before open another page it is necessary to close the previous
    // The android platform does not allow parallel rendering
    await page.close();

    final page2 = await document.getPage(2);
    final page2Image = await page2.render(width: page2.width, height: page2.height);
    await page2.close();
    runApp(
      MaterialApp(
        home: Scaffold(
          body: Center(
            child: PageView(
              children: <Widget>[
                Image(
                  image: MemoryImage(pageImage.bytes),
                ),
                Image(
                  image: MemoryImage(page2Image.bytes),
                )
              ],
            ),
          ),
        ),
        // Images are rendered with an alpha channel. 
        // White background is needed for black tex to be seen.
        color: Colors.white,
      )
    );
  } on PlatformException catch (error) {
    // Handle render error
    print(error);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  native_pdf_renderer: ^1.4.1

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

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (meta).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
extension ^0.0.4 0.0.5
flutter 0.0.0
meta ^1.1.6 1.1.6 1.1.7
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
pedantic ^1.4.0

Admin