A PDF viewer in Flutter that does not require any external native dependencies.
The demo showcases all features of the library including:
- Loading PDFs from URLs
- Custom navigation controls
- Download functionality
- Loading from bytes/assets
- And more!
See DEMO_FEATURES.md for a detailed breakdown of all demonstrated features.
- π± Pure Flutter/Dart implementation - no native code required
- π Load PDFs from URLs
- π Load PDFs from bytes/local files
- πΎ Download PDFs to device storage
- π Page navigation controls
- π¨ Customizable viewer appearance
Add this to your package's pubspec.yaml file:
dependencies:
flutterish_pdf_viewer: ^0.1.0Then run:
flutter pub getimport 'package:flutter/material.dart';
import 'package:flutterish_pdf_viewer/flutterish_pdf_viewer.dart';
class MyPdfViewer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('PDF Viewer')),
body: PdfViewerFromUrl(
url: 'https://example.com/sample.pdf',
showControls: true,
onLoaded: () => print('PDF loaded successfully'),
onError: (error) => print('Error: $error'),
),
);
}
}import 'package:flutter/material.dart';
import 'package:flutterish_pdf_viewer/flutterish_pdf_viewer.dart';
class AdvancedPdfViewer extends StatefulWidget {
@override
_AdvancedPdfViewerState createState() => _AdvancedPdfViewerState();
}
class _AdvancedPdfViewerState extends State<AdvancedPdfViewer> {
final PdfController _controller = PdfController();
@override
void initState() {
super.initState();
_loadPdf();
}
Future<void> _loadPdf() async {
await _controller.loadFromUrl('https://example.com/sample.pdf');
}
Future<void> _downloadPdf() async {
final path = await _controller.downloadPdf('my_document.pdf');
if (path != null) {
print('PDF saved to: $path');
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('PDF Viewer'),
actions: [
IconButton(
icon: Icon(Icons.download),
onPressed: _downloadPdf,
),
],
),
body: PdfViewer(
controller: _controller,
showControls: true,
backgroundColor: Colors.grey[200],
),
);
}
}import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutterish_pdf_viewer/flutterish_pdf_viewer.dart';
class BytesPdfViewer extends StatelessWidget {
final Uint8List pdfBytes;
const BytesPdfViewer({required this.pdfBytes});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('PDF from Bytes')),
body: PdfViewerFromBytes(
bytes: pdfBytes,
showControls: true,
),
);
}
}The main widget for displaying PDF documents.
Properties:
controller(required): PdfController instance managing the documentshowControls(optional): Whether to show page navigation controls (default: true)backgroundColor(optional): Background color for the viewer
Controller for managing PDF documents and navigation.
Methods:
loadFromUrl(String url): Load a PDF from a URLloadFromBytes(Uint8List bytes): Load a PDF from bytesdownloadPdf(String filename): Download the current PDF to device storagegoToPage(int page): Navigate to a specific pagenextPage(): Navigate to the next pagepreviousPage(): Navigate to the previous page
Properties:
document: The current PDF documentisLoading: Whether a document is currently loadingerror: Any error message from the last operationcurrentPage: The current page number (0-indexed)
Convenience widget for loading PDFs directly from a URL.
Properties:
url(required): The URL of the PDF to loadshowControls(optional): Whether to show page navigation controlsonLoaded(optional): Callback when the PDF is successfully loadedonError(optional): Callback when an error occurs
Convenience widget for loading PDFs from bytes.
Properties:
bytes(required): The PDF bytes to loadshowControls(optional): Whether to show page navigation controls
Check out the example directory for a complete sample application.
Live Demo: https://evaisse.github.io/flutterish_pdf_viewer/
To run the example locally:
cd example
flutter runTo run on web:
cd example
flutter run -d chromeWant to deploy your own version? See GITHUB_PAGES_SETUP.md for instructions on setting up GitHub Pages for this demo.
Note: This package currently provides a framework for PDF viewing without native dependencies. Full PDF rendering (displaying actual PDF content as rendered pages) requires a PDF parsing and rendering library. The current implementation displays PDF metadata and provides the infrastructure for:
- Loading PDFs from various sources
- Navigation between pages
- Downloading PDFs
- Managing PDF state
For complete PDF rendering, you may need to:
- Implement a pure Dart PDF parser
- Use an existing PDF rendering library
- Convert PDFs to images on a backend server
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Created by evaisse