layoutPdf method
Future<bool>
layoutPdf(
- Printer? printer,
- LayoutCallback onLayout,
- String name,
- PdfPageFormat format,
- bool dynamicLayout,
- bool usePrinterSettings,
- OutputType outputType,
- bool forceCustomPrintPaper,
override
Prints a Pdf document to a local printer using the platform UI the Pdf document is re-built in a LayoutCallback each time the user changes a setting like the page format or orientation.
returns a future with a bool
set to true if the document is printed
and false if it is canceled.
throws an exception in case of error
Implementation
@override
Future<bool> layoutPdf(
Printer? printer,
LayoutCallback onLayout,
String name,
PdfPageFormat format,
bool dynamicLayout,
bool usePrinterSettings,
OutputType outputType,
bool forceCustomPrintPaper,
) async {
final job = _printJobs.add(
onCompleted: Completer<bool>(),
onLayout: onLayout,
);
final params = <String, dynamic>{
if (printer != null) 'printer': printer.url,
'name': name,
'job': job.index,
'width': format.width,
'height': format.height,
'marginLeft': format.marginLeft,
'marginTop': format.marginTop,
'marginRight': format.marginRight,
'marginBottom': format.marginBottom,
'dynamic': dynamicLayout,
'usePrinterSettings': usePrinterSettings,
'outputType': outputType.index,
'forceCustomPrintPaper': forceCustomPrintPaper,
};
await _channel.invokeMethod<int>('printPdf', params);
try {
return await job.onCompleted!.future;
} finally {
_printJobs.remove(job.index);
}
}