Matteo Ricupero
Committed by GitHub

added new printing output type value with print pdf method (#1693)

* added new printing output type value with print pdf method

* removed logs

* fix test with new output type value
@@ -149,12 +149,19 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -149,12 +149,19 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
149 return paperList[0] 149 return paperList[0]
150 } 150 }
151 151
  152 + for paper in paperList {
  153 + if (paper.paperSize.width == currentSize!.width && paper.paperSize.height == currentSize!.height) ||
  154 + (paper.paperSize.width == currentSize!.height && paper.paperSize.height == currentSize!.width) {
  155 + return paper
  156 + }
  157 + }
  158 +
152 let bestPaper = UIPrintPaper.bestPaper(forPageSize: currentSize!, withPapersFrom: paperList) 159 let bestPaper = UIPrintPaper.bestPaper(forPageSize: currentSize!, withPapersFrom: paperList)
153 160
154 return bestPaper 161 return bestPaper
155 } 162 }
156 163
157 - func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool) { 164 + func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool, outputType type: UIPrintInfo.OutputType) {
158 currentSize = size 165 currentSize = size
159 dynamic = dyn 166 dynamic = dyn
160 let printing = UIPrintInteractionController.isPrintingAvailable 167 let printing = UIPrintInteractionController.isPrintingAvailable
@@ -175,7 +182,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -175,7 +182,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
175 182
176 let printInfo = UIPrintInfo.printInfo() 183 let printInfo = UIPrintInfo.printInfo()
177 printInfo.jobName = jobName! 184 printInfo.jobName = jobName!
178 - printInfo.outputType = .general 185 + printInfo.outputType = type
179 if orientation != nil { 186 if orientation != nil {
180 printInfo.orientation = orientation! 187 printInfo.orientation = orientation!
181 orientation = nil 188 orientation = nil
@@ -60,6 +60,22 @@ public class PrintingPlugin: NSObject, FlutterPlugin { @@ -60,6 +60,22 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
60 let marginBottom = CGFloat((args["marginBottom"] as! NSNumber).floatValue) 60 let marginBottom = CGFloat((args["marginBottom"] as! NSNumber).floatValue)
61 let printJob = PrintJob(printing: self, index: args["job"] as! Int) 61 let printJob = PrintJob(printing: self, index: args["job"] as! Int)
62 let dynamic = args["dynamic"] as! Bool 62 let dynamic = args["dynamic"] as! Bool
  63 +
  64 +
  65 + let outputType: UIPrintInfo.OutputType
  66 + switch (args["outputType"] as! Int) {
  67 + case 0:
  68 + outputType = UIPrintInfo.OutputType.general
  69 + case 1:
  70 + outputType = UIPrintInfo.OutputType.photo
  71 + case 2:
  72 + outputType = UIPrintInfo.OutputType.grayscale
  73 + case 3:
  74 + outputType = UIPrintInfo.OutputType.photoGrayscale
  75 + default:
  76 + outputType = UIPrintInfo.OutputType.general
  77 + }
  78 +
63 jobs[args["job"] as! UInt32] = printJob 79 jobs[args["job"] as! UInt32] = printJob
64 printJob.printPdf(name: name, 80 printJob.printPdf(name: name,
65 withPageSize: CGSize( 81 withPageSize: CGSize(
@@ -71,8 +87,10 @@ public class PrintingPlugin: NSObject, FlutterPlugin { @@ -71,8 +87,10 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
71 y: marginTop, 87 y: marginTop,
72 width: width - marginRight - marginLeft, 88 width: width - marginRight - marginLeft,
73 height: height - marginBottom - marginTop 89 height: height - marginBottom - marginTop
74 - ), withPrinter: printer,  
75 - dynamically: dynamic) 90 + ),
  91 + withPrinter: printer,
  92 + dynamically: dynamic,
  93 + outputType: outputType)
76 result(NSNumber(value: 1)) 94 result(NSNumber(value: 1))
77 } else if call.method == "sharePdf" { 95 } else if call.method == "sharePdf" {
78 let object = args["doc"] as! FlutterStandardTypedData 96 let object = args["doc"] as! FlutterStandardTypedData
@@ -24,6 +24,7 @@ export 'src/asset_utils.dart'; @@ -24,6 +24,7 @@ export 'src/asset_utils.dart';
24 export 'src/cache.dart'; 24 export 'src/cache.dart';
25 export 'src/callback.dart'; 25 export 'src/callback.dart';
26 export 'src/fonts/gfonts.dart'; 26 export 'src/fonts/gfonts.dart';
  27 +export 'src/output_type.dart';
27 export 'src/preview/action_bar_theme.dart'; 28 export 'src/preview/action_bar_theme.dart';
28 export 'src/preview/actions.dart'; 29 export 'src/preview/actions.dart';
29 export 'src/preview/pdf_preview.dart'; 30 export 'src/preview/pdf_preview.dart';
@@ -29,6 +29,7 @@ import 'package:web/web.dart' as web; @@ -29,6 +29,7 @@ import 'package:web/web.dart' as web;
29 import 'src/callback.dart'; 29 import 'src/callback.dart';
30 import 'src/interface.dart'; 30 import 'src/interface.dart';
31 import 'src/mutex.dart'; 31 import 'src/mutex.dart';
  32 +import 'src/output_type.dart';
32 import 'src/pdfjs.dart'; 33 import 'src/pdfjs.dart';
33 import 'src/printer.dart'; 34 import 'src/printer.dart';
34 import 'src/printing_info.dart'; 35 import 'src/printing_info.dart';
@@ -156,6 +157,7 @@ class PrintingPlugin extends PrintingPlatform { @@ -156,6 +157,7 @@ class PrintingPlugin extends PrintingPlatform {
156 PdfPageFormat format, 157 PdfPageFormat format,
157 bool dynamicLayout, 158 bool dynamicLayout,
158 bool usePrinterSettings, 159 bool usePrinterSettings,
  160 + OutputType outputType,
159 ) async { 161 ) async {
160 late Uint8List result; 162 late Uint8List result;
161 try { 163 try {
@@ -23,6 +23,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -23,6 +23,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
23 23
24 import 'callback.dart'; 24 import 'callback.dart';
25 import 'method_channel.dart'; 25 import 'method_channel.dart';
  26 +import 'output_type.dart';
26 import 'printer.dart'; 27 import 'printer.dart';
27 import 'printing_info.dart'; 28 import 'printing_info.dart';
28 import 'raster.dart'; 29 import 'raster.dart';
@@ -66,6 +67,7 @@ abstract class PrintingPlatform extends PlatformInterface { @@ -66,6 +67,7 @@ abstract class PrintingPlatform extends PlatformInterface {
66 PdfPageFormat format, 67 PdfPageFormat format,
67 bool dynamicLayout, 68 bool dynamicLayout,
68 bool usePrinterSettings, 69 bool usePrinterSettings,
  70 + OutputType outputType,
69 ); 71 );
70 72
71 /// Enumerate the available printers on the system. 73 /// Enumerate the available printers on the system.
@@ -31,6 +31,7 @@ import 'package:pdf/pdf.dart'; @@ -31,6 +31,7 @@ import 'package:pdf/pdf.dart';
31 import 'callback.dart'; 31 import 'callback.dart';
32 import 'interface.dart'; 32 import 'interface.dart';
33 import 'method_channel_ffi.dart' if (dart.library.js) 'method_channel_js.dart'; 33 import 'method_channel_ffi.dart' if (dart.library.js) 'method_channel_js.dart';
  34 +import 'output_type.dart';
34 import 'print_job.dart'; 35 import 'print_job.dart';
35 import 'printer.dart'; 36 import 'printer.dart';
36 import 'printing_info.dart'; 37 import 'printing_info.dart';
@@ -180,6 +181,7 @@ class MethodChannelPrinting extends PrintingPlatform { @@ -180,6 +181,7 @@ class MethodChannelPrinting extends PrintingPlatform {
180 PdfPageFormat format, 181 PdfPageFormat format,
181 bool dynamicLayout, 182 bool dynamicLayout,
182 bool usePrinterSettings, 183 bool usePrinterSettings,
  184 + OutputType outputType,
183 ) async { 185 ) async {
184 final job = _printJobs.add( 186 final job = _printJobs.add(
185 onCompleted: Completer<bool>(), 187 onCompleted: Completer<bool>(),
@@ -198,6 +200,7 @@ class MethodChannelPrinting extends PrintingPlatform { @@ -198,6 +200,7 @@ class MethodChannelPrinting extends PrintingPlatform {
198 'marginBottom': format.marginBottom, 200 'marginBottom': format.marginBottom,
199 'dynamic': dynamicLayout, 201 'dynamic': dynamicLayout,
200 'usePrinterSettings': usePrinterSettings, 202 'usePrinterSettings': usePrinterSettings,
  203 + 'outputType': outputType.index,
201 }; 204 };
202 205
203 await _channel.invokeMethod<int>('printPdf', params); 206 await _channel.invokeMethod<int>('printPdf', params);
  1 +enum OutputType {
  2 + generic,
  3 + photo,
  4 + grayscale,
  5 + photoGrayscale,
  6 +}
@@ -22,6 +22,7 @@ import 'package:pdf/pdf.dart'; @@ -22,6 +22,7 @@ import 'package:pdf/pdf.dart';
22 22
23 import 'callback.dart'; 23 import 'callback.dart';
24 import 'interface.dart'; 24 import 'interface.dart';
  25 +import 'output_type.dart';
25 import 'printer.dart'; 26 import 'printer.dart';
26 import 'printing_info.dart'; 27 import 'printing_info.dart';
27 import 'raster.dart'; 28 import 'raster.dart';
@@ -39,12 +40,16 @@ mixin Printing { @@ -39,12 +40,16 @@ mixin Printing {
39 /// Set [usePrinterSettings] to true to use the configuration defined by 40 /// Set [usePrinterSettings] to true to use the configuration defined by
40 /// the printer. May not work for all the printers and can depend on the 41 /// the printer. May not work for all the printers and can depend on the
41 /// drivers. (Supported platforms: Windows) 42 /// drivers. (Supported platforms: Windows)
  43 + /// Set [outputType] to [OutputType.generic] to use the default printing
  44 + /// system, or [OutputType.photos] to use the photo printing system.
  45 + /// (Supported platforms: iOS)
42 static Future<bool> layoutPdf({ 46 static Future<bool> layoutPdf({
43 required LayoutCallback onLayout, 47 required LayoutCallback onLayout,
44 String name = 'Document', 48 String name = 'Document',
45 PdfPageFormat format = PdfPageFormat.standard, 49 PdfPageFormat format = PdfPageFormat.standard,
46 bool dynamicLayout = true, 50 bool dynamicLayout = true,
47 bool usePrinterSettings = false, 51 bool usePrinterSettings = false,
  52 + OutputType outputType = OutputType.generic,
48 }) { 53 }) {
49 return PrintingPlatform.instance.layoutPdf( 54 return PrintingPlatform.instance.layoutPdf(
50 null, 55 null,
@@ -53,6 +58,7 @@ mixin Printing { @@ -53,6 +58,7 @@ mixin Printing {
53 format, 58 format,
54 dynamicLayout, 59 dynamicLayout,
55 usePrinterSettings, 60 usePrinterSettings,
  61 + outputType,
56 ); 62 );
57 } 63 }
58 64
@@ -139,6 +145,7 @@ mixin Printing { @@ -139,6 +145,7 @@ mixin Printing {
139 PdfPageFormat format = PdfPageFormat.standard, 145 PdfPageFormat format = PdfPageFormat.standard,
140 bool dynamicLayout = true, 146 bool dynamicLayout = true,
141 bool usePrinterSettings = false, 147 bool usePrinterSettings = false,
  148 + OutputType outputType = OutputType.generic,
142 }) { 149 }) {
143 return PrintingPlatform.instance.layoutPdf( 150 return PrintingPlatform.instance.layoutPdf(
144 printer, 151 printer,
@@ -147,6 +154,7 @@ mixin Printing { @@ -147,6 +154,7 @@ mixin Printing {
147 format, 154 format,
148 dynamicLayout, 155 dynamicLayout,
149 usePrinterSettings, 156 usePrinterSettings,
  157 + outputType,
150 ); 158 );
151 } 159 }
152 160
@@ -15,7 +15,7 @@ topics: @@ -15,7 +15,7 @@ topics:
15 - print 15 - print
16 - printing 16 - printing
17 - report 17 - report
18 -version: 5.13.1 18 +version: 5.13.2
19 19
20 environment: 20 environment:
21 sdk: ">=3.3.0 <4.0.0" 21 sdk: ">=3.3.0 <4.0.0"
@@ -108,6 +108,7 @@ class MockPrinting extends Mock @@ -108,6 +108,7 @@ class MockPrinting extends Mock
108 PdfPageFormat format, 108 PdfPageFormat format,
109 bool dynamicLayout, 109 bool dynamicLayout,
110 bool usePrinterSettings, 110 bool usePrinterSettings,
  111 + OutputType outputType,
111 ) async => 112 ) async =>
112 true; 113 true;
113 114