Skip to content

Commit

Permalink
Fix readme tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavBfr committed Jul 24, 2023
1 parent 9d3ca6a commit 90ad768
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions pdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ Create a Uint8List from the image
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));
pw.Image image1 = pw.Image(pw.MemoryImage(imageBytes));
```

implement the image in a container

```dart
pw.Container(
alignment: pw.Alignment.center,
height: 200,
child: image,
),
child: image1,
);
```

To load an image from the network using the `printing` package:
Expand Down Expand Up @@ -191,7 +194,7 @@ To save the pdf file (Web):
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)}")
href: "data:application/octet-stream;charset=utf-16le;base64,${base64.encode(fileInts)}")
..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf")
..click();
```
Expand Down
6 changes: 5 additions & 1 deletion test/extract_readme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ void buildFile(String src, String dest, bool flutter) {

final output = File(dest);
final st = output.openWrite();
st.writeln('// ignore_for_file: avoid_web_libraries_in_flutter');
st.writeln('import \'dart:io\';');
st.writeln('import \'dart:typed_data\';');
st.writeln('import \'package:flutter/services.dart\' show rootBundle;');
if (flutter) {
st.writeln('import \'package:flutter/services.dart\' show rootBundle;');
st.writeln('import \'package:path_provider/path_provider.dart\';');
} else {
st.writeln('import \'dart:convert\';');
st.writeln('import \'dart:html\' as html;');
}
st.writeln('import \'package:printing/printing.dart\';');
st.writeln('import \'package:pdf/pdf.dart\';');
Expand Down

0 comments on commit 90ad768

Please sign in to comment.