downloadPdfWeb function

void downloadPdfWeb(
  1. List<int> bytes,
  2. String filename
)

Download PDF file on web platform.

Implementation

void downloadPdfWeb(List<int> bytes, String filename) {
  // Convert Uint8List to JSUint8Array.
  final jsBytes = (bytes as Uint8List).toJS;
  final blob = web.Blob(
    [jsBytes].toJS,
    web.BlobPropertyBag(type: 'application/pdf'),
  );
  final url = web.URL.createObjectURL(blob);
  final anchor = web.document.createElement('a') as web.HTMLAnchorElement
    ..href = url
    ..download = filename;
  anchor.click();
  web.URL.revokeObjectURL(url);
}