Skip to content

Commit 90ad768

Browse files
committedJul 24, 2023
Fix readme tests
1 parent 9d3ca6a commit 90ad768

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
 

‎pdf/README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,21 @@ Create a Uint8List from the image
7979
final img = await rootBundle.load('assets/images/logo.jpg');
8080
final imageBytes = img.buffer.asUint8List();
8181
```
82+
8283
Create an image from the ImageBytes
8384

8485
```dart
85-
pw.Image image = pw.Image(pw.MemoryImage(imageBytes));
86+
pw.Image image1 = pw.Image(pw.MemoryImage(imageBytes));
8687
```
88+
8789
implement the image in a container
90+
8891
```dart
8992
pw.Container(
9093
alignment: pw.Alignment.center,
9194
height: 200,
92-
child: image,
93-
),
95+
child: image1,
96+
);
9497
```
9598

9699
To load an image from the network using the `printing` package:
@@ -191,7 +194,7 @@ To save the pdf file (Web):
191194
var savedFile = await pdf.save();
192195
List<int> fileInts = List.from(savedFile);
193196
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)}")
195198
..setAttribute("download", "${DateTime.now().millisecondsSinceEpoch}.pdf")
196199
..click();
197200
```

‎test/extract_readme.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ void buildFile(String src, String dest, bool flutter) {
4848

4949
final output = File(dest);
5050
final st = output.openWrite();
51+
st.writeln('// ignore_for_file: avoid_web_libraries_in_flutter');
5152
st.writeln('import \'dart:io\';');
5253
st.writeln('import \'dart:typed_data\';');
54+
st.writeln('import \'package:flutter/services.dart\' show rootBundle;');
5355
if (flutter) {
54-
st.writeln('import \'package:flutter/services.dart\' show rootBundle;');
5556
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;');
5660
}
5761
st.writeln('import \'package:printing/printing.dart\';');
5862
st.writeln('import \'package:pdf/pdf.dart\';');

0 commit comments

Comments
 (0)