Showing
12 changed files
with
83 additions
and
10 deletions
1 | # Changelog | 1 | # Changelog |
2 | 2 | ||
3 | -## 5.0.5 | 3 | +## 5.1.0 |
4 | 4 | ||
5 | - Fix PdfPreview timer dispose [wwl901215] | 5 | - Fix PdfPreview timer dispose [wwl901215] |
6 | - Remove unnecessary _raster call in PdfPreview [yaymalaga] | 6 | - Remove unnecessary _raster call in PdfPreview [yaymalaga] |
7 | +- Added subject, body and email parameters in sharePdf [Deepak] | ||
8 | +- Subject, body and emails parameter to pdf preview [Deepak] | ||
7 | 9 | ||
8 | ## 5.0.4 | 10 | ## 5.0.4 |
9 | 11 |
@@ -49,7 +49,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler { | @@ -49,7 +49,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler { | ||
49 | case "sharePdf": { | 49 | case "sharePdf": { |
50 | final byte[] document = call.argument("doc"); | 50 | final byte[] document = call.argument("doc"); |
51 | final String name = call.argument("name"); | 51 | final String name = call.argument("name"); |
52 | - PrintingJob.sharePdf(activity, document, name); | 52 | + final String subject = call.argument("subject"); |
53 | + final String body = call.argument("body"); | ||
54 | + final ArrayList<String> emails = call.argument("emails"); | ||
55 | + PrintingJob.sharePdf(activity, document, name, subject, body, emails); | ||
53 | result.success(1); | 56 | result.success(1); |
54 | break; | 57 | break; |
55 | } | 58 | } |
@@ -207,7 +207,8 @@ public class PrintingJob extends PrintDocumentAdapter { | @@ -207,7 +207,8 @@ public class PrintingJob extends PrintDocumentAdapter { | ||
207 | printing.onCompleted(PrintingJob.this, false, message); | 207 | printing.onCompleted(PrintingJob.this, false, message); |
208 | } | 208 | } |
209 | 209 | ||
210 | - static void sharePdf(final Context context, final byte[] data, final String name) { | 210 | + static void sharePdf(final Context context, final byte[] data, final String name, |
211 | + final String subject, final String body, final ArrayList<String> emails) { | ||
211 | assert name != null; | 212 | assert name != null; |
212 | 213 | ||
213 | try { | 214 | try { |
@@ -233,6 +234,10 @@ public class PrintingJob extends PrintDocumentAdapter { | @@ -233,6 +234,10 @@ public class PrintingJob extends PrintDocumentAdapter { | ||
233 | shareIntent.setType("application/pdf"); | 234 | shareIntent.setType("application/pdf"); |
234 | shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI); | 235 | shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI); |
235 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 236 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
237 | + shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject); | ||
238 | + shareIntent.putExtra(Intent.EXTRA_TEXT, body); | ||
239 | + shareIntent.putExtra( | ||
240 | + Intent.EXTRA_EMAIL, emails != null ? emails.toArray(new String[0]) : null); | ||
236 | Intent chooserIntent = Intent.createChooser(shareIntent, null); | 241 | Intent chooserIntent = Intent.createChooser(shareIntent, null); |
237 | List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities( | 242 | List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities( |
238 | chooserIntent, PackageManager.MATCH_DEFAULT_ONLY); | 243 | chooserIntent, PackageManager.MATCH_DEFAULT_ONLY); |
@@ -186,7 +186,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -186,7 +186,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
186 | ) | 186 | ) |
187 | } | 187 | } |
188 | 188 | ||
189 | - static func sharePdf(data: Data, withSourceRect rect: CGRect, andName name: String) { | 189 | + static func sharePdf(data: Data, withSourceRect rect: CGRect, andName name: String, subject: String?, body: String?) { |
190 | let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) | 190 | let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) |
191 | let fileURL = tmpDirURL.appendingPathComponent(name) | 191 | let fileURL = tmpDirURL.appendingPathComponent(name) |
192 | 192 | ||
@@ -197,7 +197,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -197,7 +197,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
197 | return | 197 | return |
198 | } | 198 | } |
199 | 199 | ||
200 | - let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil) | 200 | + let activityViewController = UIActivityViewController(activityItems: [fileURL, body], applicationActivities: nil) |
201 | + activityViewController.setValue(subject, forKey: "subject") | ||
201 | if UI_USER_INTERFACE_IDIOM() == .pad { | 202 | if UI_USER_INTERFACE_IDIOM() == .pad { |
202 | let controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController | 203 | let controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController |
203 | activityViewController.popoverPresentationController?.sourceView = controller?.view | 204 | activityViewController.popoverPresentationController?.sourceView = controller?.view |
@@ -84,7 +84,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { | @@ -84,7 +84,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { | ||
84 | width: CGFloat((args["w"] as? NSNumber)?.floatValue ?? 0.0), | 84 | width: CGFloat((args["w"] as? NSNumber)?.floatValue ?? 0.0), |
85 | height: CGFloat((args["h"] as? NSNumber)?.floatValue ?? 0.0) | 85 | height: CGFloat((args["h"] as? NSNumber)?.floatValue ?? 0.0) |
86 | ), | 86 | ), |
87 | - andName: args["name"] as! String | 87 | + andName: args["name"] as! String, |
88 | + subject: args["subject"] as? String, | ||
89 | + body: args["body"] as? String | ||
88 | ) | 90 | ) |
89 | result(NSNumber(value: 1)) | 91 | result(NSNumber(value: 1)) |
90 | } else if call.method == "convertHtml" { | 92 | } else if call.method == "convertHtml" { |
@@ -159,6 +159,9 @@ class PrintingPlugin extends PrintingPlatform { | @@ -159,6 +159,9 @@ class PrintingPlugin extends PrintingPlatform { | ||
159 | Uint8List bytes, | 159 | Uint8List bytes, |
160 | String filename, | 160 | String filename, |
161 | Rect bounds, | 161 | Rect bounds, |
162 | + String? subject, | ||
163 | + String? body, | ||
164 | + List<String>? emails, | ||
162 | ) async { | 165 | ) async { |
163 | final pdfFile = html.Blob( | 166 | final pdfFile = html.Blob( |
164 | <Uint8List>[Uint8List.fromList(bytes)], | 167 | <Uint8List>[Uint8List.fromList(bytes)], |
@@ -73,11 +73,26 @@ abstract class PrintingPlatform extends PlatformInterface { | @@ -73,11 +73,26 @@ abstract class PrintingPlatform extends PlatformInterface { | ||
73 | /// Opens the native printer picker interface, and returns the URL of the selected printer. | 73 | /// Opens the native printer picker interface, and returns the URL of the selected printer. |
74 | Future<Printer?> pickPrinter(Rect bounds); | 74 | Future<Printer?> pickPrinter(Rect bounds); |
75 | 75 | ||
76 | - /// Displays a platform popup to share the Pdf document to another application | 76 | + /// Displays a platform popup to share the Pdf document to another application. |
77 | + /// | ||
78 | + /// [subject] will be the email subject if selected application is email. | ||
79 | + /// | ||
80 | + /// [body] will be the extra text that can be shared along with the Pdf document. | ||
81 | + /// For email application [body] will be the email body text. | ||
82 | + /// | ||
83 | + /// [emails] will be the list of emails to which you want to share the Pdf document. | ||
84 | + /// If the selected application is email application then the these [emails] will be | ||
85 | + /// filled in the to address. | ||
86 | + /// | ||
87 | + /// [subject] and [body] will only work for Android and iOS platforms. | ||
88 | + /// [emails] will only work for Android Platform. | ||
77 | Future<bool> sharePdf( | 89 | Future<bool> sharePdf( |
78 | Uint8List bytes, | 90 | Uint8List bytes, |
79 | String filename, | 91 | String filename, |
80 | Rect bounds, | 92 | Rect bounds, |
93 | + String? subject, | ||
94 | + String? body, | ||
95 | + List<String>? emails, | ||
81 | ); | 96 | ); |
82 | 97 | ||
83 | /// Convert an html document to a pdf data | 98 | /// Convert an html document to a pdf data |
@@ -225,10 +225,16 @@ class MethodChannelPrinting extends PrintingPlatform { | @@ -225,10 +225,16 @@ class MethodChannelPrinting extends PrintingPlatform { | ||
225 | Uint8List bytes, | 225 | Uint8List bytes, |
226 | String filename, | 226 | String filename, |
227 | Rect bounds, | 227 | Rect bounds, |
228 | + String? subject, | ||
229 | + String? body, | ||
230 | + List<String>? emails, | ||
228 | ) async { | 231 | ) async { |
229 | final params = <String, dynamic>{ | 232 | final params = <String, dynamic>{ |
230 | 'doc': Uint8List.fromList(bytes), | 233 | 'doc': Uint8List.fromList(bytes), |
231 | 'name': filename, | 234 | 'name': filename, |
235 | + 'subject': subject, | ||
236 | + 'body': body, | ||
237 | + 'emails': emails, | ||
232 | 'x': bounds.left, | 238 | 'x': bounds.left, |
233 | 'y': bounds.top, | 239 | 'y': bounds.top, |
234 | 'w': bounds.width, | 240 | 'w': bounds.width, |
@@ -36,6 +36,9 @@ class PdfPreview extends StatefulWidget { | @@ -36,6 +36,9 @@ class PdfPreview extends StatefulWidget { | ||
36 | this.useActions = true, | 36 | this.useActions = true, |
37 | this.pages, | 37 | this.pages, |
38 | this.dynamicLayout = true, | 38 | this.dynamicLayout = true, |
39 | + this.shareActionExtraBody, | ||
40 | + this.shareActionExtraSubject, | ||
41 | + this.shareActionExtraEmails, | ||
39 | }) : super(key: key); | 42 | }) : super(key: key); |
40 | 43 | ||
41 | /// Called when a pdf document is needed | 44 | /// Called when a pdf document is needed |
@@ -97,6 +100,17 @@ class PdfPreview extends StatefulWidget { | @@ -97,6 +100,17 @@ class PdfPreview extends StatefulWidget { | ||
97 | /// channel message while opened. | 100 | /// channel message while opened. |
98 | final bool dynamicLayout; | 101 | final bool dynamicLayout; |
99 | 102 | ||
103 | + /// email subject when email application is selected from the share dialog | ||
104 | + final String? shareActionExtraSubject; | ||
105 | + | ||
106 | + /// extra text to share with Pdf document | ||
107 | + final String? shareActionExtraBody; | ||
108 | + | ||
109 | + /// list of email addresses which will be filled automatically if the email application | ||
110 | + /// is selected from the share dialog. | ||
111 | + /// This will work only for Android platform. | ||
112 | + final List<String>? shareActionExtraEmails; | ||
113 | + | ||
100 | @override | 114 | @override |
101 | _PdfPreviewState createState() => _PdfPreviewState(); | 115 | _PdfPreviewState createState() => _PdfPreviewState(); |
102 | } | 116 | } |
@@ -590,6 +604,9 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -590,6 +604,9 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
590 | bytes: bytes, | 604 | bytes: bytes, |
591 | bounds: bounds, | 605 | bounds: bounds, |
592 | filename: widget.pdfFileName ?? 'document.pdf', | 606 | filename: widget.pdfFileName ?? 'document.pdf', |
607 | + body: widget.shareActionExtraBody, | ||
608 | + subject: widget.shareActionExtraSubject, | ||
609 | + emails: widget.shareActionExtraEmails, | ||
593 | ); | 610 | ); |
594 | 611 | ||
595 | if (result && widget.onShared != null) { | 612 | if (result && widget.onShared != null) { |
@@ -135,11 +135,26 @@ mixin Printing { | @@ -135,11 +135,26 @@ mixin Printing { | ||
135 | ); | 135 | ); |
136 | } | 136 | } |
137 | 137 | ||
138 | - /// Displays a platform popup to share the Pdf document to another application | 138 | + /// Displays a platform popup to share the Pdf document to another application. |
139 | + /// | ||
140 | + /// [subject] will be the email subject if selected application is email. | ||
141 | + /// | ||
142 | + /// [body] will be the extra text that can be shared along with the Pdf document. | ||
143 | + /// For email application [body] will be the email body text. | ||
144 | + /// | ||
145 | + /// [emails] will be the list of emails to which you want to share the Pdf document. | ||
146 | + /// If the selected application is email application then the these [emails] will be | ||
147 | + /// filled in the to address. | ||
148 | + /// | ||
149 | + /// [subject] and [body] will only work for Android and iOS platforms. | ||
150 | + /// [emails] will only work for Android Platform. | ||
139 | static Future<bool> sharePdf({ | 151 | static Future<bool> sharePdf({ |
140 | required Uint8List bytes, | 152 | required Uint8List bytes, |
141 | String filename = 'document.pdf', | 153 | String filename = 'document.pdf', |
142 | Rect? bounds, | 154 | Rect? bounds, |
155 | + String? subject, | ||
156 | + String? body, | ||
157 | + List<String>? emails, | ||
143 | }) { | 158 | }) { |
144 | bounds ??= Rect.fromCircle(center: Offset.zero, radius: 10); | 159 | bounds ??= Rect.fromCircle(center: Offset.zero, radius: 10); |
145 | 160 | ||
@@ -147,6 +162,9 @@ mixin Printing { | @@ -147,6 +162,9 @@ mixin Printing { | ||
147 | bytes, | 162 | bytes, |
148 | filename, | 163 | filename, |
149 | bounds, | 164 | bounds, |
165 | + subject, | ||
166 | + body, | ||
167 | + emails, | ||
150 | ); | 168 | ); |
151 | } | 169 | } |
152 | 170 |
@@ -7,7 +7,7 @@ description: > | @@ -7,7 +7,7 @@ description: > | ||
7 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing | 7 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing |
8 | repository: https://github.com/DavBfr/dart_pdf | 8 | repository: https://github.com/DavBfr/dart_pdf |
9 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 9 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
10 | -version: 5.0.5 | 10 | +version: 5.1.0 |
11 | 11 | ||
12 | environment: | 12 | environment: |
13 | sdk: ">=2.12.0-0 <3.0.0" | 13 | sdk: ">=2.12.0-0 <3.0.0" |
@@ -118,7 +118,8 @@ class MockPrinting extends Mock | @@ -118,7 +118,8 @@ class MockPrinting extends Mock | ||
118 | true; | 118 | true; |
119 | 119 | ||
120 | @override | 120 | @override |
121 | - Future<bool> sharePdf(Uint8List bytes, String filename, Rect bounds) async => | 121 | + Future<bool> sharePdf(Uint8List bytes, String filename, Rect bounds, |
122 | + String? subject, String? body, List<String>? emails) async => | ||
122 | true; | 123 | true; |
123 | 124 | ||
124 | @override | 125 | @override |
-
Please register or login to post a comment