Committed by
GitHub
Web support instructions
added instructions - add image on Flutter Web added instructions - save on Flutter Web
Showing
1 changed file
with
36 additions
and
2 deletions
| @@ -57,7 +57,7 @@ pdf.addPage(pw.Page( | @@ -57,7 +57,7 @@ pdf.addPage(pw.Page( | ||
| 57 | })); // Page | 57 | })); // Page |
| 58 | ``` | 58 | ``` |
| 59 | 59 | ||
| 60 | -To load an image from a file: | 60 | +To load an image from a file (Mobile): |
| 61 | 61 | ||
| 62 | ```dart | 62 | ```dart |
| 63 | final image = pw.MemoryImage( | 63 | final image = pw.MemoryImage( |
| @@ -71,6 +71,28 @@ pdf.addPage(pw.Page(build: (pw.Context context) { | @@ -71,6 +71,28 @@ pdf.addPage(pw.Page(build: (pw.Context context) { | ||
| 71 | })); // Page | 71 | })); // Page |
| 72 | ``` | 72 | ``` |
| 73 | 73 | ||
| 74 | +To load an image from asset file (web): | ||
| 75 | + | ||
| 76 | +Create a Uint8List from the image | ||
| 77 | + | ||
| 78 | +```dart | ||
| 79 | +final img = await rootBundle.load('assets/images/logo.jpg'); | ||
| 80 | +final imageBytes = img.buffer.asUint8List(); | ||
| 81 | +``` | ||
| 82 | +Create an image from the ImageBytes | ||
| 83 | + | ||
| 84 | +```dart | ||
| 85 | +pw.Image image = pw.Image(pw.MemoryImage(imageBytes)); | ||
| 86 | +``` | ||
| 87 | +implement the image in a container | ||
| 88 | +```dart | ||
| 89 | +pw.Container( | ||
| 90 | + alignment: pw.Alignment.center, | ||
| 91 | + height: 200, | ||
| 92 | + child: image, | ||
| 93 | +), | ||
| 94 | +``` | ||
| 95 | + | ||
| 74 | To load an image from the network using the `printing` package: | 96 | To load an image from the network using the `printing` package: |
| 75 | 97 | ||
| 76 | ```dart | 98 | ```dart |
| @@ -152,7 +174,7 @@ pdf.addPage(pw.Page( | @@ -152,7 +174,7 @@ pdf.addPage(pw.Page( | ||
| 152 | })); // Page | 174 | })); // Page |
| 153 | ``` | 175 | ``` |
| 154 | 176 | ||
| 155 | -To save the pdf file: | 177 | +To save the pdf file (Mobile): |
| 156 | 178 | ||
| 157 | ```dart | 179 | ```dart |
| 158 | // On Flutter, use the [path_provider](https://pub.dev/packages/path_provider) library: | 180 | // On Flutter, use the [path_provider](https://pub.dev/packages/path_provider) library: |
| @@ -162,6 +184,18 @@ final file = File("example.pdf"); | @@ -162,6 +184,18 @@ final file = File("example.pdf"); | ||
| 162 | await file.writeAsBytes(await pdf.save()); | 184 | await file.writeAsBytes(await pdf.save()); |
| 163 | ``` | 185 | ``` |
| 164 | 186 | ||
| 187 | +To save the pdf file (Web): | ||
| 188 | +(saved as a unique name based on milliseconds since epoch) | ||
| 189 | + | ||
| 190 | +```dart | ||
| 191 | +var savedFile = await pdf.save(); | ||
| 192 | +List<int> fileInts = List.from(savedFile); | ||
| 193 | +html.AnchorElement( | ||
| 194 | + href: "data:application/octet-stream;charset=utf-16le;base64,${con.base64.encode(fileInts)}") | ||
| 195 | + ..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf") | ||
| 196 | + ..click(); | ||
| 197 | +``` | ||
| 198 | + | ||
| 165 | ## Encryption, Digital Signature, and loading a PDF Document | 199 | ## Encryption, Digital Signature, and loading a PDF Document |
| 166 | 200 | ||
| 167 | Encryption using RC4-40, RC4-128, AES-128, and AES-256 is fully supported using a separate library. | 201 | Encryption using RC4-40, RC4-128, AES-128, and AES-256 is fully supported using a separate library. |
-
Please register or login to post a comment