From ef8577859cc6f8f129228f7257c900cf7bc53abf Mon Sep 17 00:00:00 2001 From: Muhamad Bagus Prasetyo Date: Wed, 24 Sep 2025 14:08:22 +0700 Subject: [PATCH 1/2] Add maxZoom parameter to control maximum zoom level --- .../io/endigo/plugins/pdfviewflutter/FlutterPDFView.java | 6 ++++++ .../Sources/flutter_pdfview/FlutterPDFView.m | 6 +++++- lib/flutter_pdfview.dart | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) 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..6e32dd68 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,12 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler { pdfView.setBackgroundColor(color); } + Object maxZoom = params.get("maxZoom"); + if (maxZoom != null) { + float max = ((Number) maxZoom).floatValue(); + 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, }; } From 713cde580db33e7b1f73908da64d7bcd35b59992 Mon Sep 17 00:00:00 2001 From: Muhamad Bagus Prasetyo Date: Thu, 25 Sep 2025 09:43:21 +0700 Subject: [PATCH 2/2] docs(android): clarify why maxZoom is multiplied by 2 Added an inline comment in FlutterPDFView.java to explain that Android's PDFView uses a different zoom scale than iOS PDFKit. Multiplying by 2 makes zoom levels more visually consistent across platforms. --- .../java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java | 3 +++ 1 file changed, 3 insertions(+) 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 6e32dd68..78a58792 100644 --- a/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java +++ b/android/src/main/java/io/endigo/plugins/pdfviewflutter/FlutterPDFView.java @@ -57,6 +57,9 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler { 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); }