Skip to content

Commit 4952485

Browse files
author
LokeshPalani
committed
Added the missed files in the pdfviewer platform interface
1 parent 783b55f commit 4952485

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
3+
4+
void main() {
5+
runApp(MaterialApp(
6+
title: 'Syncfusion PDF Viewer Demo for Web',
7+
theme: ThemeData(
8+
useMaterial3: false,
9+
),
10+
home: const HomePage(),
11+
));
12+
}
13+
14+
/// Represents Homepage for Navigation
15+
class HomePage extends StatefulWidget {
16+
const HomePage({Key? key}) : super(key: key);
17+
18+
@override
19+
_HomePage createState() => _HomePage();
20+
}
21+
22+
class _HomePage extends State<HomePage> {
23+
final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
24+
25+
@override
26+
void initState() {
27+
super.initState();
28+
}
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return Scaffold(
33+
appBar: AppBar(
34+
title: const Text('Syncfusion Flutter PDF Viewer'),
35+
actions: <Widget>[
36+
IconButton(
37+
icon: const Icon(
38+
Icons.bookmark,
39+
color: Colors.white,
40+
),
41+
onPressed: () {
42+
_pdfViewerKey.currentState?.openBookmarkView();
43+
},
44+
),
45+
],
46+
),
47+
body: SfPdfViewer.network(
48+
'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf',
49+
key: _pdfViewerKey,
50+
),
51+
);
52+
}
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'src/pdfviewer_platform_interface.dart';
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'dart:async';
2+
import 'package:flutter/services.dart';
3+
import 'package:syncfusion_pdfviewer_platform_interface/pdfviewer_platform_interface.dart';
4+
5+
class MethodChannelPdfViewer extends PdfViewerPlatform {
6+
final MethodChannel _channel = MethodChannel('syncfusion_flutter_pdfviewer');
7+
8+
/// Initializes the PDF renderer instance in respective platform by loading the PDF from the provided byte information.
9+
/// If success, returns page count else returns error message from respective platform
10+
@override
11+
Future<String?> initializePdfRenderer(
12+
Uint8List documentBytes, String documentID) async {
13+
return _channel.invokeMethod('initializePdfRenderer', <String, dynamic>{
14+
'documentBytes': documentBytes,
15+
'documentID': documentID
16+
});
17+
}
18+
19+
/// Gets the height of all pages in the document.
20+
@override
21+
Future<List?> getPagesHeight(String documentID) async {
22+
return _channel.invokeMethod('getPagesHeight', documentID);
23+
}
24+
25+
/// Gets the width of all pages in the document.
26+
@override
27+
Future<List?> getPagesWidth(String documentID) async {
28+
return _channel.invokeMethod('getPagesWidth', documentID);
29+
}
30+
31+
/// Gets the image's bytes information of the specified page.
32+
@override
33+
Future<Uint8List?> getImage(
34+
int pageNumber, double currentScale, String documentID) async {
35+
return _channel.invokeMethod<Uint8List>('getImage', <String, dynamic>{
36+
'index': pageNumber,
37+
'scale': currentScale,
38+
'documentID': documentID
39+
});
40+
}
41+
42+
/// Gets the image's bytes information of the specified portion of the page
43+
@override
44+
Future<Uint8List?> getTileImage(int pageNumber, double currentScale, double x,
45+
double y, double width, double height, String documentID) async {
46+
return _channel.invokeMethod<Uint8List>('getTileImage', <String, dynamic>{
47+
'pageNumber': pageNumber,
48+
'scale': currentScale,
49+
'x': x,
50+
'y': y,
51+
'width': width,
52+
'height': height,
53+
'documentID': documentID
54+
});
55+
}
56+
57+
/// Closes the PDF document.
58+
@override
59+
Future<void> closeDocument(String documentID) async {
60+
return _channel.invokeMethod('closeDocument', documentID);
61+
}
62+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
library syncfusion_pdfviewer_platform_interface;
2+
3+
import 'dart:async';
4+
import 'dart:typed_data';
5+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
6+
import 'package:syncfusion_pdfviewer_platform_interface/src/method_channel_pdfviewer.dart';
7+
8+
/// The interface that implementations of syncfusion_flutter_pdfviewer must implement.
9+
///
10+
/// Platform implementations should extend this class rather than implement it as `syncfusion_flutter_pdfviewer`
11+
/// does not consider newly added methods to be breaking changes. Extending this class
12+
/// (using `extends`) ensures that the subclass will get the default implementation, while
13+
/// platform implementations that `implements` this interface will be broken by newly added
14+
/// [PdfViewerPlatform] methods
15+
abstract class PdfViewerPlatform extends PlatformInterface {
16+
/// Constructs a PdfViewerPlatform.
17+
PdfViewerPlatform() : super(token: _token);
18+
static PdfViewerPlatform _instance = MethodChannelPdfViewer();
19+
20+
static final Object _token = Object();
21+
22+
/// The default instance of [PdfViewerPlatform] to use.
23+
///
24+
/// Defaults to [MethodChannelPdfViewer]
25+
static PdfViewerPlatform get instance => _instance;
26+
27+
/// Platform-specific plugins should set this with their own platform-specific
28+
/// class that extends [PdfViewerPlatform] when they register themselves.
29+
static set instance(PdfViewerPlatform instance) {
30+
PlatformInterface.verifyToken(instance, _token);
31+
_instance = instance;
32+
}
33+
34+
/// Initializes the PDF renderer instance in respective platform by loading the PDF from the specified path.
35+
///
36+
/// If success, returns page count else returns error message from respective platform
37+
Future<String?> initializePdfRenderer(
38+
Uint8List documentBytes, String documentID) async {
39+
throw UnimplementedError(
40+
'initializePdfRenderer() has not been implemented.');
41+
}
42+
43+
/// Gets the height of all pages in the document.
44+
Future<List?> getPagesHeight(String documentID) async {
45+
throw UnimplementedError('getPagesHeight() has not been implemented.');
46+
}
47+
48+
/// Gets the width of all pages in the document.
49+
Future<List?> getPagesWidth(String documentID) async {
50+
throw UnimplementedError('getPagesWidth() has not been implemented.');
51+
}
52+
53+
/// Gets the image's bytes information of the specified page.
54+
Future<Uint8List?> getImage(
55+
int pageNumber, double scale, String documentID) async {
56+
throw UnimplementedError('getImage() has not been implemented.');
57+
}
58+
59+
/// Gets the image's bytes information of the specified portion of the page.
60+
Future<Uint8List?> getTileImage(int pageNumber, double scale, double x,
61+
double y, double width, double height, String documentID) async {
62+
throw UnimplementedError('getTileImage() has not been implemented.');
63+
}
64+
65+
/// Closes the PDF document.
66+
Future<void> closeDocument(String documentID) async {
67+
throw UnimplementedError('closeDocument() has not been implemented.');
68+
}
69+
}

0 commit comments

Comments
 (0)