interactive_pdf_viewer 0.1.1+1 copy "interactive_pdf_viewer: ^0.1.1+1" to clipboard
interactive_pdf_viewer: ^0.1.1+1 copied to clipboard

A Flutter package for displaying PDFs with the ability to retrieve sentences by tapping on their position.

interactive_pdf_viewer #

A Flutter plugin for viewing PDF files using the native iOS PDFKit framework, which provides a high-quality and performant PDF rendering experience on iOS devices.

Note: This plugin only works on iOS 11.0 and above, as it uses PDFKit which was introduced in iOS 11. The plugin will throw an error if used on earlier iOS versions or on Android.

Features #

  • Open PDFs from local file paths
  • Download and open PDFs from URLs
  • Open PDFs from Flutter assets
  • Native iOS PDFKit integration for optimal performance
  • Full-screen PDF viewer with zoom, scroll, and page navigation
  • Close button to dismiss the PDF viewer

Installation #

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

dependencies:
  flutter_ios_pdfkit: ^0.1.0

Or

flutter pub add flutter_ios_pdfkit

iOS #

Update your iOS deployment target in your Podfile to iOS 11 or higher:

platform :ios, '11.0'

Usage #

Import the package #

import 'package:flutter_ios_pdfkit/flutter_ios_pdfkit.dart';

Open a PDF file from a local path #

try {
  await FlutterIosPdfkit.openPDF('/path/to/local/file.pdf');
} on PlatformException catch (e) {
  print('Error opening PDF: ${e.message}');
}

Download and open a PDF from a URL #

try {
  await FlutterIosPdfkit.openPDFFromUrl('https://example.com/sample.pdf');
} catch (e) {
  print('Error opening PDF from URL: $e');
}

Open a PDF asset #

First, add the PDF to your Flutter assets in pubspec.yaml:

flutter:
  assets:
    - assets/sample.pdf

Then, open it:

try {
  await FlutterIosPdfkit.openPDFAsset('assets/sample.pdf');
} catch (e) {
  print('Error opening PDF asset: $e');
}

Check if platform is supported #

Since this plugin only works on iOS, you might want to check the platform before using it:

if (FlutterIosPdfkit.isIOS) {
  await FlutterIosPdfkit.openPDFFromUrl('https://example.com/sample.pdf');
} else {
  // Use an alternative PDF viewer for Android
}

Example #

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: PDFViewerScreen(),
    );
  }
}

class PDFViewerScreen extends StatelessWidget {
  final String pdfUrl = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('PDF Viewer Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () async {
                try {
                  // Check if platform is iOS
                  if (FlutterIosPdfkit.isIOS) {
                    await FlutterIosPdfkit.openPDFFromUrl(pdfUrl);
                  } else {
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('This feature is only available on iOS')),
                    );
                  }
                } catch (e) {
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text('Error opening PDF: $e')),
                  );
                }
              },
              child: Text('Open Sample PDF'),
            ),
          ],
        ),
      ),
    );
  }
}

Limitations #

  • Only available on iOS 11.0 and above
  • No support for Android (returns an error)
  • Limited customization of the PDF viewer interface

License #

This project is licensed under the MIT License - see the LICENSE file for details.

2
likes
0
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for displaying PDFs with the ability to retrieve sentences by tapping on their position.

Homepage
Repository (GitHub)
View/report issues

Topics

#pdf #viewer #interactive #text-selection #flutter

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, flutter_pdfview, flutter_tts, http, path_provider, pdf_text, synchronized

More

Packages that depend on interactive_pdf_viewer

Packages that implement interactive_pdf_viewer