alh_pdf_view 2.3.3

SDKflutter
Platformandroidios

Has the functionality to show PDF with bytes of a file path as widget with some extra functionalities.

Pub Version GitHub branch checks state

With this widget, you can display a PDF with bytes or a path.

Index

Introduction

The package alh_pdf_view includes:

  • Displays PDF with bytes or path

See more about the functionalities in the parameter section.

Android

  • implemented in Kotlin with the dependency AndroidPdfViewer of barteksc
  • supports Android 16 KB memory page size

iOS

  • implemented in Swift with the dependency PDFKit

⚠️ Android Setup

This package depends on a library hosted on JitPack. To make it work on Android, you must add JitPack to your Gradle repositories.

Open your android/build.gradle file and ensure the repositories block contains:

allprojects {
    repositories {
        ...
        // Add this line
        maven { url 'https://jitpack.io' }
        ...
    }
}

Example


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

class AlhPdfViewExample extends StatelessWidget {
  const AlhPdfViewExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('PDF Example')),
      body: const AlhPdfView(
        filePath: 'ADD_PATH_TO_FILE',
      ),
    );
  }
}

Parameters

This is a list of all parameters that can be used for this widget. Consider that some paremters only work for one platform.

ParameterDescriptionDefault Value
filePathOptional path to load PDF file.-
bytesOptional bytes to load PDF file.-
fitPolicyDefines how the PDF should fit inside the widget.FitPolicy.both
fitEachPageEach page of the PDF will fit inside the given space. (only Android)true
enableSwipeThe current page will be changed when swiping.true
swipeHorizontalIf true, all pages are displayed in horizontal direction.false
nightModeInverting colors of pages to have the look of a dark mode. (only Android)false
autoSpacingIf true, spacing will be added to fit each page on its own on the screen. (only Android)true
pageFlingMaking a fling change.true
pageSnapSnap pages to screen boundaries when changing the current page. (only Android)true
defaultPageDescribes which page should be shown at first.0
defaultZoomFactorDefines how much the displayed PDF page should zoomed when rendered.1.0
backgroundColorSetting backgroundColor of remaining space around the pdf view.Colors.transparent
passwordUnlocks PDF page with this password.""
enableDoubleTapWhen double tapping, the zoom of the page changes. (only Android)1.0
minZoomMin zoom value that the user can reach while zooming.0.5
maxZoomMax zoom value that the user can reach while zooming.4.0
enableDefaultScrollHandleAdds a button to scroll faster through the document. (only Android)false
showScrollbarIf true, a Scrollbar is visible for the Pdf View (only iOS).true
spacingSpacing between pdf pages.0

This is a list of functional parameters.

ParameterDescriptionDefault Value
gestureRecognizersWhich gestures should be consumed by the pdf view.-
onViewCreatedIf not null invoked once the native view is created.-
onRenderCallback once the PDF page was loaded.-
onPageChangedWhen changing the page, this method will be called with the new page.-
onZoomChangedCalled when changing the zoom.-
onErrorWhen there are errors happening, this methods returns a message.-
onLinkHandleCalled when tapping a link in PDF. (only iOS)-

AlhPdfViewController

If you want to start specific actions for the displayed PDF file, you can use AlhPdfViewController. This controller contains some functionalities to update your view. Here is a list of them.

ParameterDescription
getPageCountReturns the number of pages for the PDF.
getCurrentPageReturns the current displayed page.
setPageJumping to the page optionally animated.
goToNextPageNavigates to the next page of the PDF.
goToPreviousPageNavigates to the previous page of the PDF.
resetZoomSetting the scale factor to the default zoom factor.
setZoomZooming to the given zoom.
getZoomReturns the current zoom value.
getPageSizeReturns the size of the given [page] index. (only iOS)
setOrientationRebuilds pdf after the orientation was changed to ensure it is correctly displayed. (only Android for internal use)
updateCreationParamsReacts to any changes for bytes, filePath, fitPolicy and showScrollbar. (only for internal use)
disposeCalled to cancel all subscription and disposing on the native part after the AlhPdfView was disposed (only for internal use)