diff --git a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java index b5551826..78a58792 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -54,6 +54,15 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler { pdfView.setBackgroundColor(color); } + Object maxZoom = params.get("maxZoom"); + if (maxZoom != null) { + float max = ((Number) maxZoom).floatValue(); + // NOTE: Android's PDFView zoom scaling is about half of iOS PDFKit. + // Multiply by 2 to normalize so that a Dart value like maxZoom = 3.0 + // results in ~300% zoom on both iOS and Android. + pdfView.setMaxZoom(max * 2); + } + if (config != null) { config .enableSwipe(getBoolean(params, "enableSwipe")) diff --git a/ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m b/ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m index 3f393ae0..e6e57c74 100644 --- a/ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m +++ b/ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m @@ -165,7 +165,11 @@ - (instancetype)initWithFrame:(CGRect)frame } _pdfView.document = document; - _pdfView.maxScaleFactor = [args[@"maxZoom"] doubleValue]; + NSNumber *maxZoom = args[@"maxZoom"]; + if (maxZoom != nil && [maxZoom isKindOfClass:[NSNumber class]]) { + _pdfView.maxScaleFactor = [maxZoom doubleValue]; + } + _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit; NSString* password = args[@"password"]; diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index fc064290..69240524 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -39,7 +39,9 @@ class PDFView extends StatefulWidget { this.fitPolicy = FitPolicy.WIDTH, this.preventLinkNavigation = false, this.backgroundColor, + this.maxZoom = 3.0, }) : assert(filePath != null || pdfData != null), + assert(maxZoom > 1.0, 'maxZoom must be greater than 1.0'), super(key: key); @override @@ -119,6 +121,9 @@ class PDFView extends StatefulWidget { /// Use to change the background color. ex : "#FF0000" => red final Color? backgroundColor; + + /// Use to change the maximal zoom. Must be greater than 1.0, default 3.0. + final double maxZoom; } class _PDFViewState extends State { @@ -237,6 +242,7 @@ class _PDFViewSettings { this.fitPolicy, this.preventLinkNavigation, this.backgroundColor, + this.maxZoom, }); static _PDFViewSettings fromWidget(PDFView widget) { @@ -252,6 +258,7 @@ class _PDFViewSettings { fitPolicy: widget.fitPolicy, preventLinkNavigation: widget.preventLinkNavigation, backgroundColor: widget.backgroundColor, + maxZoom: widget.maxZoom, ); } @@ -267,6 +274,7 @@ class _PDFViewSettings { final bool? preventLinkNavigation; final Color? backgroundColor; + final double? maxZoom; Map toMap() { return { @@ -281,6 +289,7 @@ class _PDFViewSettings { 'fitPolicy': fitPolicy.toString(), 'preventLinkNavigation': preventLinkNavigation, 'backgroundColor': backgroundColor?.value, + 'maxZoom': maxZoom, }; }