Showing
2 changed files
with
12 additions
and
5 deletions
@@ -79,18 +79,21 @@ Create a Uint8List from the image | @@ -79,18 +79,21 @@ Create a Uint8List from the image | ||
79 | final img = await rootBundle.load('assets/images/logo.jpg'); | 79 | final img = await rootBundle.load('assets/images/logo.jpg'); |
80 | final imageBytes = img.buffer.asUint8List(); | 80 | final imageBytes = img.buffer.asUint8List(); |
81 | ``` | 81 | ``` |
82 | + | ||
82 | Create an image from the ImageBytes | 83 | Create an image from the ImageBytes |
83 | 84 | ||
84 | ```dart | 85 | ```dart |
85 | -pw.Image image = pw.Image(pw.MemoryImage(imageBytes)); | 86 | +pw.Image image1 = pw.Image(pw.MemoryImage(imageBytes)); |
86 | ``` | 87 | ``` |
88 | + | ||
87 | implement the image in a container | 89 | implement the image in a container |
90 | + | ||
88 | ```dart | 91 | ```dart |
89 | pw.Container( | 92 | pw.Container( |
90 | alignment: pw.Alignment.center, | 93 | alignment: pw.Alignment.center, |
91 | height: 200, | 94 | height: 200, |
92 | - child: image, | ||
93 | -), | 95 | + child: image1, |
96 | +); | ||
94 | ``` | 97 | ``` |
95 | 98 | ||
96 | To load an image from the network using the `printing` package: | 99 | To load an image from the network using the `printing` package: |
@@ -191,7 +194,7 @@ To save the pdf file (Web): | @@ -191,7 +194,7 @@ To save the pdf file (Web): | ||
191 | var savedFile = await pdf.save(); | 194 | var savedFile = await pdf.save(); |
192 | List<int> fileInts = List.from(savedFile); | 195 | List<int> fileInts = List.from(savedFile); |
193 | html.AnchorElement( | 196 | html.AnchorElement( |
194 | - href: "data:application/octet-stream;charset=utf-16le;base64,${con.base64.encode(fileInts)}") | 197 | + href: "data:application/octet-stream;charset=utf-16le;base64,${base64.encode(fileInts)}") |
195 | ..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf") | 198 | ..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf") |
196 | ..click(); | 199 | ..click(); |
197 | ``` | 200 | ``` |
@@ -48,11 +48,15 @@ void buildFile(String src, String dest, bool flutter) { | @@ -48,11 +48,15 @@ void buildFile(String src, String dest, bool flutter) { | ||
48 | 48 | ||
49 | final output = File(dest); | 49 | final output = File(dest); |
50 | final st = output.openWrite(); | 50 | final st = output.openWrite(); |
51 | + st.writeln('// ignore_for_file: avoid_web_libraries_in_flutter'); | ||
51 | st.writeln('import \'dart:io\';'); | 52 | st.writeln('import \'dart:io\';'); |
52 | st.writeln('import \'dart:typed_data\';'); | 53 | st.writeln('import \'dart:typed_data\';'); |
54 | + st.writeln('import \'package:flutter/services.dart\' show rootBundle;'); | ||
53 | if (flutter) { | 55 | if (flutter) { |
54 | - st.writeln('import \'package:flutter/services.dart\' show rootBundle;'); | ||
55 | st.writeln('import \'package:path_provider/path_provider.dart\';'); | 56 | st.writeln('import \'package:path_provider/path_provider.dart\';'); |
57 | + } else { | ||
58 | + st.writeln('import \'dart:convert\';'); | ||
59 | + st.writeln('import \'dart:html\' as html;'); | ||
56 | } | 60 | } |
57 | st.writeln('import \'package:printing/printing.dart\';'); | 61 | st.writeln('import \'package:printing/printing.dart\';'); |
58 | st.writeln('import \'package:pdf/pdf.dart\';'); | 62 | st.writeln('import \'package:pdf/pdf.dart\';'); |
-
Please register or login to post a comment