native_pdf_renderer 2.1.1 copy "native_pdf_renderer: ^2.1.1" to clipboard
native_pdf_renderer: ^2.1.1 copied to clipboard

outdated

Flutter plugin to render PDF pages as images on both Android and iOS devices.

PDF Renderer #

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

We also support the package for easy display PDF documents native_pdf_view

For IOS need set swift version to 5 (instruction, issue)

Getting Started #

In your flutter project add the dependency:

pub package

dependencies:
  native_pdf_renderer: any

Usage example #

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);
  }
}

Api #

PdfDocument #

Parameter Description Default
sourceName Needed for toString method. Contains a method for opening a document (file, data or asset) -
id Document unique id. Generated when opening document. -
pagesCount All pages count in document. Starts from 1. -
isClosed Is the document closed -

Document open:

// From assets
PdfDocument.openAsset('assets/sample.pdf')

// From file
PdfDocument.openFile('path/to/file/on/device')

// From data
PdfDocument.openData(uint8Data)

Open page:

final page = document.getPage(pageNumber); // Starts from 1

Close document:

document.close();

PdfPage #

Parameter Description Default
document Parent document Parent
id Page unique id. Needed for rendering and closing page. Generated when opening page. -
width Page source width in pixels, int -
height Page source height in pixels, int -
isClosed Is the page closed false

Render image:

final pageImage = page.render(
  // rendered image width resolution, required
  width: page.width * 2,
  // rendered image height resolution, required
  height: page.height * 2,

  // Rendered image compression format, also can be PNG, WEBP*
  // Optional, default: PdfPageFormat.PNG
  format: PdfPageFormat.JPEG,

  // Image background fill color for JPEG
  // Optional, default '#ffffff'
  backgroundColor: '#ffffff',

  // Crop rect in image for render
  // Optional, default null
  cropRect: Rect.fromLTRB(left, top, right, bottom),
);

PdfPageImage #

Parameter Description Default
id Page unique id. Needed for rendering and closing page. Generated when render page. -
pageNumber Page number. The first page is 1. -
width Width of the rendered area in pixels, int -
height Height of the rendered area in pixels, int -
bytes Rendered image result, Uint8List -
format Rendered image compression format PdfPageFormat.PNG

Close page:
Before open new page android asks to close the past.
If this is not done, the application may crash with an error

page.close();

* PdfPageFormat.WEBP support only on android

Rendering additional info #

Rendering PDF files on Android devices #

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.

Rendering PDF files on IOS devices #

This plugin uses the IOS native PDFKit to render the pages of PDF files and provides a widget called PDFKit to display the PDF page you like.

103
likes
0
pub points
90%
popularity

Publisher

verified publisherserge.software

Flutter plugin to render PDF pages as images on both Android and iOS devices.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

extension, flutter, meta, synchronized

More

Packages that depend on native_pdf_renderer