|
@@ -5,26 +5,22 @@
|
|
|
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
|
|
|
// This notice may not be removed from this file.
|
|
|
|
|
|
+import 'dart:io';
|
|
|
import 'dart:ui';
|
|
|
|
|
|
import 'package:compdfkit_flutter/util/extension/cpdf_color_extension.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
+import '../document/cpdf_document.dart';
|
|
|
+
|
|
|
/// PDF Reader Widget Controller
|
|
|
+///
|
|
|
/// Examples:
|
|
|
/// ```dart
|
|
|
/// Scaffold(
|
|
|
/// resizeToAvoidBottomInset: false,
|
|
|
-/// appBar: AppBar(
|
|
|
-/// title: const Text('CPDFReaderWidget Example'),
|
|
|
-/// leading: IconButton(
|
|
|
-/// onPressed: () {
|
|
|
-/// _save();
|
|
|
-/// Navigator.pop(context);
|
|
|
-/// },
|
|
|
-/// icon: const Icon(Icons.arrow_back)),
|
|
|
-/// ),
|
|
|
+/// appBar: AppBar(title: const Text('CPDFReaderWidget Example')),
|
|
|
/// body: CPDFReaderWidget(
|
|
|
/// document: widget.documentPath,
|
|
|
/// configuration: CPDFConfiguration(),
|
|
@@ -36,13 +32,19 @@ import 'package:flutter/services.dart';
|
|
|
/// ));
|
|
|
/// ```
|
|
|
class CPDFReaderWidgetController {
|
|
|
+
|
|
|
late MethodChannel _channel;
|
|
|
|
|
|
+ late CPDFDocument _document;
|
|
|
+
|
|
|
CPDFReaderWidgetController(int id) {
|
|
|
_channel = MethodChannel('com.compdfkit.flutter.ui.pdfviewer.$id');
|
|
|
_channel.setMethodCallHandler((call) async {});
|
|
|
+ _document = CPDFDocument(_channel);
|
|
|
}
|
|
|
|
|
|
+ // CPDFDocument get document => _document;
|
|
|
+
|
|
|
/// Save document
|
|
|
/// Return value: **true** if the save is successful,
|
|
|
/// **false** if the save fails.
|
|
@@ -50,30 +52,56 @@ class CPDFReaderWidgetController {
|
|
|
return await _channel.invokeMethod('save');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// Set the page scale
|
|
|
/// Value Range: 1.0~5.0
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setScale(1.5);
|
|
|
+ /// ```
|
|
|
Future<void> setScale(double scale) async {
|
|
|
await _channel.invokeMethod('set_scale', scale);
|
|
|
}
|
|
|
|
|
|
/// Get the page scale
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// double scaleValue = await _controller.getScale();
|
|
|
+ /// ```
|
|
|
Future<double> getScale() async {
|
|
|
return await _channel.invokeMethod('get_scale');
|
|
|
}
|
|
|
|
|
|
/// Whether allow to scale.
|
|
|
- /// Defalut : true
|
|
|
+ /// Default : true
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setCanScale(canScale);
|
|
|
+ /// ```
|
|
|
Future<void> setCanScale(bool canScale) async {
|
|
|
await _channel.invokeMethod('set_can_scale', canScale);
|
|
|
}
|
|
|
|
|
|
- /// Sets background color of reader.
|
|
|
- /// The color of each document space will be set to 75% of [color] transparency
|
|
|
+ /// Sets background color of reader.
|
|
|
+ /// The color of each document space will be set to 75% of [color] transparency
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// await _controller.setReadBackgroundColor(Colors.white);
|
|
|
+ /// ```
|
|
|
Future<void> setReadBackgroundColor(Color color) async {
|
|
|
await _channel.invokeMethod('set_read_background_color', color.toHex());
|
|
|
}
|
|
|
|
|
|
/// Get background color of reader.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// Color color = await _controller.getReadBackgroundColor();
|
|
|
+ /// ```
|
|
|
Future<Color> getReadBackgroundColor() async {
|
|
|
String hexColor = await _channel.invokeMethod('get_read_background_color');
|
|
|
return HexColor.fromHex(hexColor);
|
|
@@ -81,12 +109,22 @@ class CPDFReaderWidgetController {
|
|
|
|
|
|
/// Sets whether to display highlight Form Field.
|
|
|
/// [isFormFieldHighlight] : true to display highlight Form Field.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setFormFieldHighlight(true);
|
|
|
+ /// ```
|
|
|
Future<void> setFormFieldHighlight(bool isFormFieldHighlight) async {
|
|
|
await _channel.invokeMethod(
|
|
|
'set_form_field_highlight', isFormFieldHighlight);
|
|
|
}
|
|
|
|
|
|
/// Whether to display highlight Form Field.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isFormFieldHighlight = await _controller.isFormFieldHighlight();
|
|
|
+ /// ```
|
|
|
Future<bool> isFormFieldHighlight() async {
|
|
|
return await _channel.invokeMethod('is_form_field_highlight');
|
|
|
}
|
|
@@ -94,11 +132,21 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether to display highlight Link.
|
|
|
///
|
|
|
/// [isLinkHighlight] : Whether to highlight Link.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setLinkHighlight(true);
|
|
|
+ /// ```
|
|
|
Future<void> setLinkHighlight(bool isLinkHighlight) async {
|
|
|
await _channel.invokeMethod('set_link_highlight', isLinkHighlight);
|
|
|
}
|
|
|
|
|
|
/// Whether to display highlight Link.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isLinkHighlight = await _controller.isLinkHighlight();
|
|
|
+ /// ```
|
|
|
Future<bool> isLinkHighlight() async {
|
|
|
return await _channel.invokeMethod('is_link_highlight');
|
|
|
}
|
|
@@ -106,11 +154,21 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether it is vertical scroll mode.
|
|
|
///
|
|
|
/// [isVerticalMode] : Whether it is vertical scroll mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setVerticalMode(true);
|
|
|
+ /// ```
|
|
|
Future<void> setVerticalMode(bool isVerticalMode) async {
|
|
|
await _channel.invokeMethod('set_vertical_mode', isVerticalMode);
|
|
|
}
|
|
|
|
|
|
/// Whether it is vertical scroll mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isVerticalMode = await _controller.isVerticalMode();
|
|
|
+ /// ```
|
|
|
Future<bool> isVerticalMode() async {
|
|
|
return await _channel.invokeMethod('is_vertical_mode');
|
|
|
}
|
|
@@ -118,6 +176,11 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets the spacing between pages
|
|
|
///
|
|
|
/// [spacing] the spacing between pages
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setPageSpacing(10);
|
|
|
+ /// ```
|
|
|
Future<void> setPageSpacing(int spacing) async {
|
|
|
await _channel.invokeMethod('set_page_spacing', spacing);
|
|
|
}
|
|
@@ -125,11 +188,21 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether it is continuous scroll mode.
|
|
|
///
|
|
|
/// [isContinueMode] Whether it is continuous scroll mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setContinueMode(true);
|
|
|
+ /// ```
|
|
|
Future<void> setContinueMode(bool isContinueMode) async {
|
|
|
await _channel.invokeMethod('set_continue_mode', isContinueMode);
|
|
|
}
|
|
|
|
|
|
/// Whether it is continuous scroll mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isContinueMode = await _controller.isContinueMode();
|
|
|
+ /// ```
|
|
|
Future<bool> isContinueMode() async {
|
|
|
return await _channel.invokeMethod('is_continue_mode');
|
|
|
}
|
|
@@ -137,21 +210,41 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether it is double page mode.
|
|
|
///
|
|
|
/// [isDoublePageMode] Whether it is double page mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setDoublePageMode(true);
|
|
|
+ /// ```
|
|
|
Future<void> setDoublePageMode(bool isDoublePageMode) async {
|
|
|
await _channel.invokeMethod('set_double_page_mode', isDoublePageMode);
|
|
|
}
|
|
|
|
|
|
/// Whether it is double page mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isDoublePageMode = await _controller.isDoublePageMode();
|
|
|
+ /// ```
|
|
|
Future<bool> isDoublePageMode() async {
|
|
|
return await _channel.invokeMethod('is_double_page_mode');
|
|
|
}
|
|
|
|
|
|
/// Sets whether it is cover page mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setCoverPageMode(true);
|
|
|
+ /// ```
|
|
|
Future<void> setCoverPageMode(bool coverPageMode) async {
|
|
|
await _channel.invokeMethod('set_cover_page_mode', coverPageMode);
|
|
|
}
|
|
|
|
|
|
/// Whether it is cover page mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isCoverPageMode = await _controller.isCoverPageMode();
|
|
|
+ /// ```
|
|
|
Future<bool> isCoverPageMode() async {
|
|
|
return await _channel.invokeMethod('is_cover_page_mode');
|
|
|
}
|
|
@@ -159,11 +252,21 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether it is crop mode.
|
|
|
///
|
|
|
/// [cropMode] Whether it is crop mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setCropMode(true);
|
|
|
+ /// ```
|
|
|
Future<void> setCropMode(bool isCropMode) async {
|
|
|
await _channel.invokeMethod('set_crop_mode', isCropMode);
|
|
|
}
|
|
|
|
|
|
/// Whether it is crop mode.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isCropMode = await _controller.isCropMode();
|
|
|
+ /// ```
|
|
|
Future<bool> isCropMode() async {
|
|
|
return await _channel.invokeMethod('is_crop_mode');
|
|
|
}
|
|
@@ -172,6 +275,11 @@ class CPDFReaderWidgetController {
|
|
|
///
|
|
|
/// [pageIndex] The index of the page to jump.
|
|
|
/// [isRecordLastJumpPageNum] Whether to record the page index before jumping to destination page.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setDisplayPageIndex(1);
|
|
|
+ /// ```
|
|
|
Future<void> setDisplayPageIndex(int pageIndex,
|
|
|
{bool isRecordLastJumpPageNum = true}) async {
|
|
|
await _channel.invokeMethod('set_display_page_index', {
|
|
@@ -181,6 +289,11 @@ class CPDFReaderWidgetController {
|
|
|
}
|
|
|
|
|
|
/// get current page index
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// int currentPageIndex = await _controller.getCurrentPageIndex();
|
|
|
+ /// ```
|
|
|
Future<int> getCurrentPageIndex() async {
|
|
|
return await _channel.invokeMethod('get_current_page_index');
|
|
|
}
|
|
@@ -188,11 +301,22 @@ class CPDFReaderWidgetController {
|
|
|
/// In the single page mode, set whether all pages keep the same width and the original page keeps the same width as readerView
|
|
|
///
|
|
|
/// [isSame] true: All pages keep the same width, the original state keeps the same width as readerView; false: Show in the actual width of page
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// _controller.setPageSameWidth(true);
|
|
|
+ /// ```
|
|
|
Future<void> setPageSameWidth(bool isSame) async {
|
|
|
+ assert(Platform.isAndroid, 'This method is only supported on Android');
|
|
|
await _channel.invokeMethod('set_page_same_width', isSame);
|
|
|
}
|
|
|
|
|
|
/// Gets whether the specified [pageIndex] is displayed on the screen
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// bool isPageInScreen = await _controller.isPageInScreen(1);
|
|
|
+ /// ```
|
|
|
Future<bool> isPageInScreen(int pageIndex) async {
|
|
|
return await _channel.invokeMethod('is_page_in_screen', pageIndex);
|
|
|
}
|
|
@@ -200,17 +324,21 @@ class CPDFReaderWidgetController {
|
|
|
/// Sets whether to fix the position of the non-swipe direction when zooming in for reading.
|
|
|
///
|
|
|
/// [isFixedScroll] true: fixed position; false: not fixed position; Set false by default
|
|
|
+ ///
|
|
|
Future<void> setFixedScroll(bool isFixedScroll) async {
|
|
|
await _channel.invokeMethod('set_fixed_scroll', isFixedScroll);
|
|
|
}
|
|
|
|
|
|
/// Gets the size of the specified page. By default, it retrieves the original size of the unzoomed PDF page.
|
|
|
/// You can obtain the zoomed size in the current view by using the [noZoom] parameter.
|
|
|
+ ///
|
|
|
+ /// example:
|
|
|
+ /// ```dart
|
|
|
+ /// Size pageSize = await _controller.getPageSize(1, noZoom: true);
|
|
|
+ /// ```
|
|
|
Future<Size> getPageSize(int pageIndex, {bool noZoom = true}) async {
|
|
|
- final Map<String, double>? pageSizeMap = await _channel.invokeMapMethod('get_page_size', {
|
|
|
- 'pageIndex': pageIndex,
|
|
|
- 'noZoom': noZoom
|
|
|
- });
|
|
|
+ final Map<String, double>? pageSizeMap = await _channel.invokeMapMethod(
|
|
|
+ 'get_page_size', {'pageIndex': pageIndex, 'noZoom': noZoom});
|
|
|
|
|
|
if (pageSizeMap == null) {
|
|
|
throw Exception('Failed to get page size');
|
|
@@ -221,6 +349,4 @@ class CPDFReaderWidgetController {
|
|
|
|
|
|
return Size(width, height);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|