Guy (Yahalom)
Committed by GitHub

Web support instructions

added instructions - add image on Flutter Web
added instructions - save on Flutter Web
... ... @@ -57,7 +57,7 @@ pdf.addPage(pw.Page(
})); // Page
```
To load an image from a file:
To load an image from a file (Mobile):
```dart
final image = pw.MemoryImage(
... ... @@ -71,6 +71,28 @@ pdf.addPage(pw.Page(build: (pw.Context context) {
})); // Page
```
To load an image from asset file (web):
Create a Uint8List from the image
```dart
final img = await rootBundle.load('assets/images/logo.jpg');
final imageBytes = img.buffer.asUint8List();
```
Create an image from the ImageBytes
```dart
pw.Image image = pw.Image(pw.MemoryImage(imageBytes));
```
implement the image in a container
```dart
pw.Container(
alignment: pw.Alignment.center,
height: 200,
child: image,
),
```
To load an image from the network using the `printing` package:
```dart
... ... @@ -152,7 +174,7 @@ pdf.addPage(pw.Page(
})); // Page
```
To save the pdf file:
To save the pdf file (Mobile):
```dart
// On Flutter, use the [path_provider](https://pub.dev/packages/path_provider) library:
... ... @@ -162,6 +184,18 @@ final file = File("example.pdf");
await file.writeAsBytes(await pdf.save());
```
To save the pdf file (Web):
(saved as a unique name based on milliseconds since epoch)
```dart
var savedFile = await pdf.save();
List<int> fileInts = List.from(savedFile);
html.AnchorElement(
href: "data:application/octet-stream;charset=utf-16le;base64,${con.base64.encode(fileInts)}")
..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf")
..click();
```
## Encryption, Digital Signature, and loading a PDF Document
Encryption using RC4-40, RC4-128, AES-128, and AES-256 is fully supported using a separate library.
... ...