David PHAM-VAN

Fix Printing on WEB

# Changelog
## 3.7.2
- Fix Printing on WEB
## 3.7.1
- Fix Pdf Raster on WEB
... ...
... ... @@ -70,19 +70,16 @@ class PrintingPlugin extends PrintingPlatform {
return false;
}
final String userAgent = js.context['navigator']['userAgent'];
final isChrome = js.context['chrome'] != null;
final isSafari = js.context['safari'] != null;
// Maybe Firefox 75 will support iframe printing
final isMobile = userAgent.contains('Mobile');
// Maybe Firefox will support iframe printing
// https://bugzilla.mozilla.org/show_bug.cgi?id=911444
// final isFirefox = userAgent.contains('Firefox');
if (!isChrome && !isSafari) {
final pr = 'data:application/pdf;base64,${base64.encode(result)}';
final html.Window win = js.context['window'];
win.open(pr, name);
return true;
}
// Chrome and Safari on a desktop computer
if ((isChrome || isSafari) && !isMobile) {
final completer = Completer<bool>();
final pdfFile = html.Blob(
<Uint8List>[Uint8List.fromList(result)],
... ... @@ -117,6 +114,21 @@ class PrintingPlugin extends PrintingPlatform {
return completer.future;
}
// All the others
final pdfFile = html.Blob(
<Uint8List>[Uint8List.fromList(result)],
'application/pdf',
);
final pdfUrl = html.Url.createObjectUrl(pdfFile);
final html.HtmlDocument doc = js.context['document'];
final html.AnchorElement link = doc.createElement('a');
link.href = pdfUrl;
link.target = '_blank';
link.click();
link.remove();
return true;
}
@override
Future<bool> sharePdf(
Uint8List bytes,
... ... @@ -133,6 +145,7 @@ class PrintingPlugin extends PrintingPlatform {
link.href = pdfUrl;
link.download = filename;
link.click();
link.remove();
return true;
}
... ...
... ... @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to
homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 3.7.1
version: 3.7.2
environment:
sdk: ">=2.3.0 <3.0.0"
... ...