pdfx 1.0.1+1 pdfx: ^1.0.1+1 copied to clipboard
Flutter plugin to render & show PDF pages as images on Web, MacOS, Windows, Android and iOS.
import 'package:flutter/material.dart';
import 'package:pdfx/pdfx.dart';
import 'package:performance/performance.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const int _initialPage = 2;
int _actualPageNumber = _initialPage, _allPagesCount = 0;
bool isSampleDoc = true;
late PdfControllerPinch _pdfController;
@override
void initState() {
_pdfController = PdfControllerPinch(
document: PdfDocument.openAsset('assets/hello.pdf'),
initialPage: _initialPage,
);
super.initState();
}
@override
void dispose() {
_pdfController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => MaterialApp(
theme: ThemeData(primaryColor: Colors.white),
darkTheme: ThemeData.dark(),
home: Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text('PdfView example'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.navigate_before),
onPressed: () {
_pdfController.previousPage(
curve: Curves.ease,
duration: const Duration(milliseconds: 100),
);
},
),
Container(
alignment: Alignment.center,
child: Text(
'$_actualPageNumber/$_allPagesCount',
style: const TextStyle(fontSize: 22),
),
),
IconButton(
icon: const Icon(Icons.navigate_next),
onPressed: () {
_pdfController.nextPage(
curve: Curves.ease,
duration: const Duration(milliseconds: 100),
);
},
),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
if (isSampleDoc) {
_pdfController.loadDocument(
PdfDocument.openAsset('assets/dummy.pdf'));
} else {
_pdfController.loadDocument(
PdfDocument.openAsset('assets/sample.pdf'));
}
isSampleDoc = !isSampleDoc;
},
)
],
),
body: CustomPerformanceOverlay(
// enabled: true,
child: PdfViewPinch(
documentLoader: const Center(child: CircularProgressIndicator()),
pageLoader: const Center(child: CircularProgressIndicator()),
controller: _pdfController,
onDocumentLoaded: (document) {
setState(() {
_allPagesCount = document.pagesCount;
});
},
onPageChanged: (page) {
setState(() {
_actualPageNumber = page;
});
},
),
),
),
);
}