David PHAM-VAN

Document.save() now returns a Future

1 # Changelog 1 # Changelog
2 2
3 -## 1.14.0 3 +## 2.0.0
4 4
5 - A borderRadius can only be given for a uniform Border 5 - A borderRadius can only be given for a uniform Border
6 - Add LayoutWidgetBuilder 6 - Add LayoutWidgetBuilder
@@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
8 - Improve internal sructure 8 - Improve internal sructure
9 - Add some asserts on the TtfParser 9 - Add some asserts on the TtfParser
10 - Add document loading 10 - Add document loading
  11 +- Remove deprecated methods
  12 +- Document.save() now returns a Future
11 13
12 ## 1.13.0 14 ## 1.13.0
13 15
@@ -89,7 +89,7 @@ To save the pdf file: @@ -89,7 +89,7 @@ To save the pdf file:
89 // final output = await getTemporaryDirectory(); 89 // final output = await getTemporaryDirectory();
90 // final file = File("${output.path}/example.pdf"); 90 // final file = File("${output.path}/example.pdf");
91 final file = File("example.pdf"); 91 final file = File("example.pdf");
92 -await file.writeAsBytes(pdf.save()); 92 +await file.writeAsBytes(await pdf.save());
93 ``` 93 ```
94 94
95 ## Encryption, Digital Signature, and loading a PDF Document 95 ## Encryption, Digital Signature, and loading a PDF Document
@@ -2,10 +2,10 @@ import 'dart:io'; @@ -2,10 +2,10 @@ import 'dart:io';
2 2
3 import 'package:pdf/widgets.dart' as pw; 3 import 'package:pdf/widgets.dart' as pw;
4 4
5 -void main() {  
6 - final doc = pw.Document(); 5 +Future<void> main() async {
  6 + final pdf = pw.Document();
7 7
8 - doc.addPage( 8 + pdf.addPage(
9 pw.Page( 9 pw.Page(
10 build: (pw.Context context) => pw.Center( 10 build: (pw.Context context) => pw.Center(
11 child: pw.Text('Hello World!'), 11 child: pw.Text('Hello World!'),
@@ -14,5 +14,5 @@ void main() { @@ -14,5 +14,5 @@ void main() {
14 ); 14 );
15 15
16 final file = File('example.pdf'); 16 final file = File('example.pdf');
17 - file.writeAsBytesSync(doc.save()); 17 + await file.writeAsBytes(await pdf.save());
18 } 18 }
@@ -191,7 +191,7 @@ class PdfDocument { @@ -191,7 +191,7 @@ class PdfDocument {
191 bool get hasGraphicStates => _graphicStates != null; 191 bool get hasGraphicStates => _graphicStates != null;
192 192
193 /// This writes the document to an OutputStream. 193 /// This writes the document to an OutputStream.
194 - void _write(PdfStream os) { 194 + Future<void> _write(PdfStream os) async {
195 final pos = PdfOutput(os); 195 final pos = PdfOutput(os);
196 196
197 // Write each object to the [PdfStream]. We call via the output 197 // Write each object to the [PdfStream]. We call via the output
@@ -199,16 +199,16 @@ class PdfDocument { @@ -199,16 +199,16 @@ class PdfDocument {
199 objects.forEach(pos.write); 199 objects.forEach(pos.write);
200 200
201 // Finally close the output, which writes the xref table. 201 // Finally close the output, which writes the xref table.
202 - pos.close(); 202 + await pos.close();
203 } 203 }
204 204
205 /// Generate the PDF document as a memory file 205 /// Generate the PDF document as a memory file
206 - Uint8List save() { 206 + Future<Uint8List> save() async {
207 final os = PdfStream(); 207 final os = PdfStream();
208 if (prev != null) { 208 if (prev != null) {
209 os.putBytes(prev.bytes); 209 os.putBytes(prev.bytes);
210 } 210 }
211 - _write(os); 211 + await _write(os);
212 return os.output(); 212 return os.output();
213 } 213 }
214 } 214 }
@@ -68,7 +68,7 @@ class PdfOutput { @@ -68,7 +68,7 @@ class PdfOutput {
68 } 68 }
69 69
70 /// This closes the Stream, writing the xref table 70 /// This closes the Stream, writing the xref table
71 - void close() { 71 + Future<void> close() async {
72 final xref = os.offset; 72 final xref = os.offset;
73 os.putString('xref\n'); 73 os.putString('xref\n');
74 74
@@ -136,7 +136,7 @@ class PdfOutput { @@ -136,7 +136,7 @@ class PdfOutput {
136 os.putString('\nstartxref\n$xref\n%%EOF\n'); 136 os.putString('\nstartxref\n$xref\n%%EOF\n');
137 137
138 if (signatureID != null) { 138 if (signatureID != null) {
139 - signatureID.writeSignature(os); 139 + await signatureID.writeSignature(os);
140 } 140 }
141 } 141 }
142 142
@@ -52,17 +52,17 @@ class PdfSignature extends PdfObject { @@ -52,17 +52,17 @@ class PdfSignature extends PdfObject {
52 _offsetEnd = os.offset; 52 _offsetEnd = os.offset;
53 } 53 }
54 54
55 - void writeSignature(PdfStream os) { 55 + Future<void> writeSignature(PdfStream os) async {
56 assert(_offsetStart != null && _offsetEnd != null, 56 assert(_offsetStart != null && _offsetEnd != null,
57 'Must reserve the object space before signing the document'); 57 'Must reserve the object space before signing the document');
58 58
59 - crypto.sign(this, os, params, _offsetStart, _offsetEnd); 59 + await crypto.sign(this, os, params, _offsetStart, _offsetEnd);
60 } 60 }
61 } 61 }
62 62
63 abstract class PdfSignatureBase { 63 abstract class PdfSignatureBase {
64 void preSign(PdfObject object, PdfDict params); 64 void preSign(PdfObject object, PdfDict params);
65 65
66 - void sign(PdfObject object, PdfStream os, PdfDict params, int offsetStart,  
67 - int offsetEnd); 66 + Future<void> sign(PdfObject object, PdfStream os, PdfDict params,
  67 + int offsetStart, int offsetEnd);
68 } 68 }
@@ -112,13 +112,13 @@ class Document { @@ -112,13 +112,13 @@ class Document {
112 _pages.add(page); 112 _pages.add(page);
113 } 113 }
114 114
115 - Uint8List save() { 115 + Future<Uint8List> save() async {
116 if (!_paint) { 116 if (!_paint) {
117 for (var page in _pages) { 117 for (var page in _pages) {
118 page.postProcess(this); 118 page.postProcess(this);
119 } 119 }
120 _paint = true; 120 _paint = true;
121 } 121 }
122 - return document.save(); 122 + return await document.save();
123 } 123 }
124 } 124 }
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf 4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
5 repository: https://github.com/DavBfr/dart_pdf 5 repository: https://github.com/DavBfr/dart_pdf
6 issue_tracker: https://github.com/DavBfr/dart_pdf/issues 6 issue_tracker: https://github.com/DavBfr/dart_pdf/issues
7 -version: 1.14.0 7 +version: 2.0.0
8 8
9 environment: 9 environment:
10 sdk: ">=2.3.0 <3.0.0" 10 sdk: ">=2.3.0 <3.0.0"
@@ -20,7 +20,7 @@ import 'package:pdf/pdf.dart'; @@ -20,7 +20,7 @@ import 'package:pdf/pdf.dart';
20 import 'package:test/test.dart'; 20 import 'package:test/test.dart';
21 21
22 void main() { 22 void main() {
23 - test('Pdf Annotations', () { 23 + test('Pdf Annotations', () async {
24 final pdf = PdfDocument(); 24 final pdf = PdfDocument();
25 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300)); 25 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300));
26 final page1 = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300)); 26 final page1 = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300));
@@ -71,6 +71,6 @@ void main() { @@ -71,6 +71,6 @@ void main() {
71 g.strokePath(); 71 g.strokePath();
72 72
73 final file = File('annotations.pdf'); 73 final file = File('annotations.pdf');
74 - file.writeAsBytesSync(pdf.save()); 74 + await file.writeAsBytes(await pdf.save());
75 }); 75 });
76 } 76 }
@@ -486,8 +486,8 @@ void main() { @@ -486,8 +486,8 @@ void main() {
486 )); 486 ));
487 }); 487 });
488 488
489 - tearDownAll(() { 489 + tearDownAll(() async {
490 final file = File('arabic.pdf'); 490 final file = File('arabic.pdf');
491 - file.writeAsBytesSync(pdf.save()); 491 + await file.writeAsBytes(await pdf.save());
492 }); 492 });
493 } 493 }
@@ -744,8 +744,8 @@ void main() { @@ -744,8 +744,8 @@ void main() {
744 }); 744 });
745 }); 745 });
746 746
747 - tearDownAll(() { 747 + tearDownAll(() async {
748 final file = File('colors.pdf'); 748 final file = File('colors.pdf');
749 - file.writeAsBytesSync(pdf.save()); 749 + await file.writeAsBytes(await pdf.save());
750 }); 750 });
751 } 751 }
@@ -23,7 +23,7 @@ import 'package:test/test.dart'; @@ -23,7 +23,7 @@ import 'package:test/test.dart';
23 import 'package:vector_math/vector_math_64.dart'; 23 import 'package:vector_math/vector_math_64.dart';
24 24
25 void main() { 25 void main() {
26 - test('Pdf Complex', () { 26 + test('Pdf Complex', () async {
27 final img = Uint32List(10 * 10); 27 final img = Uint32List(10 * 10);
28 img.fillRange(0, img.length - 1, 0x12345678); 28 img.fillRange(0, img.length - 1, 0x12345678);
29 29
@@ -96,6 +96,6 @@ void main() { @@ -96,6 +96,6 @@ void main() {
96 } 96 }
97 97
98 final file = File('complex.pdf'); 98 final file = File('complex.pdf');
99 - file.writeAsBytesSync(pdf.save()); 99 + await file.writeAsBytes(await pdf.save());
100 }); 100 });
101 } 101 }
@@ -106,9 +106,9 @@ void main() { @@ -106,9 +106,9 @@ void main() {
106 ); 106 );
107 }); 107 });
108 108
109 - tearDownAll(() { 109 + tearDownAll(() async {
110 final file = File('jpeg.pdf'); 110 final file = File('jpeg.pdf');
111 - file.writeAsBytesSync(pdf.save()); 111 + await file.writeAsBytes(await pdf.save());
112 }); 112 });
113 } 113 }
114 114
@@ -99,7 +99,7 @@ void printMetrics( @@ -99,7 +99,7 @@ void printMetrics(
99 } 99 }
100 100
101 void main() { 101 void main() {
102 - test('Pdf Font Metrics', () { 102 + test('Pdf Font Metrics', () async {
103 final pdf = Document(); 103 final pdf = Document();
104 104
105 PdfFont.courier(pdf.document); 105 PdfFont.courier(pdf.document);
@@ -126,6 +126,6 @@ void main() { @@ -126,6 +126,6 @@ void main() {
126 } 126 }
127 127
128 final file = File('metrics.pdf'); 128 final file = File('metrics.pdf');
129 - file.writeAsBytesSync(pdf.save()); 129 + await file.writeAsBytes(await pdf.save());
130 }); 130 });
131 } 131 }
@@ -20,7 +20,7 @@ import 'package:pdf/pdf.dart'; @@ -20,7 +20,7 @@ import 'package:pdf/pdf.dart';
20 import 'package:test/test.dart'; 20 import 'package:test/test.dart';
21 21
22 void main() { 22 void main() {
23 - test('Pdf Minimal', () { 23 + test('Pdf Minimal', () async {
24 final pdf = PdfDocument(compress: false); 24 final pdf = PdfDocument(compress: false);
25 final page = PdfPage(pdf, pageFormat: PdfPageFormat.a4); 25 final page = PdfPage(pdf, pageFormat: PdfPageFormat.a4);
26 26
@@ -30,6 +30,6 @@ void main() { @@ -30,6 +30,6 @@ void main() {
30 g.strokePath(); 30 g.strokePath();
31 31
32 final file = File('minimal.pdf'); 32 final file = File('minimal.pdf');
33 - file.writeAsBytesSync(pdf.save()); 33 + await file.writeAsBytes(await pdf.save());
34 }); 34 });
35 } 35 }
@@ -135,8 +135,8 @@ void main() { @@ -135,8 +135,8 @@ void main() {
135 )); 135 ));
136 }); 136 });
137 137
138 - tearDownAll(() { 138 + tearDownAll(() async {
139 final file = File('orientation.pdf'); 139 final file = File('orientation.pdf');
140 - file.writeAsBytesSync(pdf.save()); 140 + await file.writeAsBytes(await pdf.save());
141 }); 141 });
142 } 142 }
@@ -46,8 +46,8 @@ void main() { @@ -46,8 +46,8 @@ void main() {
46 build: (Context context) => Text('Hello World!'))); 46 build: (Context context) => Text('Hello World!')));
47 }); 47 });
48 48
49 - tearDownAll(() { 49 + tearDownAll(() async {
50 final file = File('roll-paper.pdf'); 50 final file = File('roll-paper.pdf');
51 - file.writeAsBytesSync(pdf.save()); 51 + await file.writeAsBytes(await pdf.save());
52 }); 52 });
53 } 53 }
@@ -59,7 +59,7 @@ void printTextTtf( @@ -59,7 +59,7 @@ void printTextTtf(
59 } 59 }
60 60
61 void main() { 61 void main() {
62 - test('Pdf TrueType', () { 62 + test('Pdf TrueType', () async {
63 final pdf = PdfDocument(); 63 final pdf = PdfDocument();
64 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300)); 64 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300));
65 65
@@ -75,7 +75,7 @@ void main() { @@ -75,7 +75,7 @@ void main() {
75 page, g, '你好 檯號 ', File('genyomintw.ttf'), 30.0 + 30.0 * top++); 75 page, g, '你好 檯號 ', File('genyomintw.ttf'), 30.0 + 30.0 * top++);
76 76
77 final file = File('ttf.pdf'); 77 final file = File('ttf.pdf');
78 - file.writeAsBytesSync(pdf.save()); 78 + await file.writeAsBytes(await pdf.save());
79 }); 79 });
80 80
81 test('Font SubSetting', () { 81 test('Font SubSetting', () {
@@ -50,7 +50,7 @@ void printText( @@ -50,7 +50,7 @@ void printText(
50 } 50 }
51 51
52 void main() { 52 void main() {
53 - test('Pdf Type1 Embedded Fonts', () { 53 + test('Pdf Type1 Embedded Fonts', () async {
54 final pdf = PdfDocument(); 54 final pdf = PdfDocument();
55 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 430)); 55 final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 430));
56 56
@@ -78,6 +78,6 @@ void main() { @@ -78,6 +78,6 @@ void main() {
78 printText(page, g, s, PdfFont.zapfDingbats(pdf), 20.0 + 30.0 * top++); 78 printText(page, g, s, PdfFont.zapfDingbats(pdf), 20.0 + 30.0 * top++);
79 79
80 final file = File('type1.pdf'); 80 final file = File('type1.pdf');
81 - file.writeAsBytesSync(pdf.save()); 81 + await file.writeAsBytes(await pdf.save());
82 }); 82 });
83 } 83 }
@@ -84,8 +84,8 @@ void main() { @@ -84,8 +84,8 @@ void main() {
84 ); 84 );
85 }); 85 });
86 86
87 - tearDownAll(() { 87 + tearDownAll(() async {
88 final file = File('widgets-barcode.pdf'); 88 final file = File('widgets-barcode.pdf');
89 - file.writeAsBytesSync(pdf.save()); 89 + await file.writeAsBytes(await pdf.save());
90 }); 90 });
91 } 91 }
@@ -201,8 +201,8 @@ void main() { @@ -201,8 +201,8 @@ void main() {
201 ))); 201 )));
202 }); 202 });
203 203
204 - tearDownAll(() { 204 + tearDownAll(() async {
205 final file = File('widgets-basic.pdf'); 205 final file = File('widgets-basic.pdf');
206 - file.writeAsBytesSync(pdf.save()); 206 + await file.writeAsBytes(await pdf.save());
207 }); 207 });
208 } 208 }
@@ -213,8 +213,8 @@ void main() { @@ -213,8 +213,8 @@ void main() {
213 }); 213 });
214 }); 214 });
215 215
216 - tearDownAll(() { 216 + tearDownAll(() async {
217 final file = File('widgets-chart.pdf'); 217 final file = File('widgets-chart.pdf');
218 - file.writeAsBytesSync(pdf.save()); 218 + await file.writeAsBytes(await pdf.save());
219 }); 219 });
220 } 220 }
@@ -69,8 +69,8 @@ void main() { @@ -69,8 +69,8 @@ void main() {
69 )); 69 ));
70 }); 70 });
71 71
72 - tearDownAll(() { 72 + tearDownAll(() async {
73 final file = File('widgets-clip.pdf'); 73 final file = File('widgets-clip.pdf');
74 - file.writeAsBytesSync(pdf.save()); 74 + await file.writeAsBytes(await pdf.save());
75 }); 75 });
76 } 76 }
@@ -199,8 +199,8 @@ void main() { @@ -199,8 +199,8 @@ void main() {
199 )); 199 ));
200 }); 200 });
201 201
202 - tearDownAll(() { 202 + tearDownAll(() async {
203 final file = File('widgets-container.pdf'); 203 final file = File('widgets-container.pdf');
204 - file.writeAsBytesSync(pdf.save()); 204 + await file.writeAsBytes(await pdf.save());
205 }); 205 });
206 } 206 }
@@ -109,8 +109,8 @@ void main() { @@ -109,8 +109,8 @@ void main() {
109 ); 109 );
110 }); 110 });
111 111
112 - tearDownAll(() { 112 + tearDownAll(() async {
113 final file = File('widgets-flex.pdf'); 113 final file = File('widgets-flex.pdf');
114 - file.writeAsBytesSync(pdf.save()); 114 + await file.writeAsBytes(await pdf.save());
115 }); 115 });
116 } 116 }
@@ -137,8 +137,8 @@ void main() { @@ -137,8 +137,8 @@ void main() {
137 }, 137 },
138 ); 138 );
139 139
140 - tearDownAll(() { 140 + tearDownAll(() async {
141 final file = File('widgets-form.pdf'); 141 final file = File('widgets-form.pdf');
142 - file.writeAsBytesSync(pdf.save()); 142 + await file.writeAsBytes(await pdf.save());
143 }); 143 });
144 } 144 }
@@ -60,8 +60,8 @@ void main() { @@ -60,8 +60,8 @@ void main() {
60 )); 60 ));
61 }); 61 });
62 62
63 - tearDownAll(() { 63 + tearDownAll(() async {
64 final file = File('widgets-gridview.pdf'); 64 final file = File('widgets-gridview.pdf');
65 - file.writeAsBytesSync(pdf.save()); 65 + await file.writeAsBytes(await pdf.save());
66 }); 66 });
67 } 67 }
@@ -66,8 +66,8 @@ void main() { @@ -66,8 +66,8 @@ void main() {
66 ); 66 );
67 }); 67 });
68 68
69 - tearDownAll(() { 69 + tearDownAll(() async {
70 final file = File('widgets-icons.pdf'); 70 final file = File('widgets-icons.pdf');
71 - file.writeAsBytesSync(pdf.save()); 71 + await file.writeAsBytes(await pdf.save());
72 }); 72 });
73 } 73 }
@@ -28,7 +28,7 @@ void main() { @@ -28,7 +28,7 @@ void main() {
28 } 28 }
29 }); 29 });
30 30
31 - test('Pdf Widgets MultiPage', () { 31 + test('Pdf Widgets MultiPage', () async {
32 Document.debug = true; 32 Document.debug = true;
33 33
34 final pdf = Document(); 34 final pdf = Document();
@@ -36,13 +36,13 @@ void main() { @@ -36,13 +36,13 @@ void main() {
36 pdf.addPage(MultiPage(build: (Context context) => lines)); 36 pdf.addPage(MultiPage(build: (Context context) => lines));
37 37
38 final file = File('widgets-multipage.pdf'); 38 final file = File('widgets-multipage.pdf');
39 - file.writeAsBytesSync(pdf.save()); 39 + await file.writeAsBytes(await pdf.save());
40 40
41 final file1 = File('widgets-multipage-1.pdf'); 41 final file1 = File('widgets-multipage-1.pdf');
42 - file1.writeAsBytesSync(pdf.save()); 42 + await file1.writeAsBytes(await pdf.save());
43 }); 43 });
44 44
45 - test('Pdf Widgets MonoPage', () { 45 + test('Pdf Widgets MonoPage', () async {
46 Document.debug = true; 46 Document.debug = true;
47 47
48 final pdf = Document(); 48 final pdf = Document();
@@ -50,9 +50,9 @@ void main() { @@ -50,9 +50,9 @@ void main() {
50 pdf.addPage(Page(build: (Context context) => Column(children: lines))); 50 pdf.addPage(Page(build: (Context context) => Column(children: lines)));
51 51
52 final file = File('widgets-monopage.pdf'); 52 final file = File('widgets-monopage.pdf');
53 - file.writeAsBytesSync(pdf.save()); 53 + await file.writeAsBytes(await pdf.save());
54 54
55 final file1 = File('widgets-monopage-1.pdf'); 55 final file1 = File('widgets-monopage-1.pdf');
56 - file1.writeAsBytesSync(pdf.save()); 56 + await file1.writeAsBytes(await pdf.save());
57 }); 57 });
58 } 58 }
@@ -44,8 +44,8 @@ void main() { @@ -44,8 +44,8 @@ void main() {
44 ); 44 );
45 }); 45 });
46 46
47 - tearDownAll(() { 47 + tearDownAll(() async {
48 final file = File('widgets-opacity.pdf'); 48 final file = File('widgets-opacity.pdf');
49 - file.writeAsBytesSync(pdf.save()); 49 + await file.writeAsBytes(await pdf.save());
50 }); 50 });
51 } 51 }
@@ -83,8 +83,8 @@ void main() { @@ -83,8 +83,8 @@ void main() {
83 ); 83 );
84 }); 84 });
85 85
86 - tearDownAll(() { 86 + tearDownAll(() async {
87 final file = File('widgets-outline.pdf'); 87 final file = File('widgets-outline.pdf');
88 - file.writeAsBytesSync(pdf.save()); 88 + await file.writeAsBytes(await pdf.save());
89 }); 89 });
90 } 90 }
@@ -54,8 +54,8 @@ void main() { @@ -54,8 +54,8 @@ void main() {
54 ); 54 );
55 }); 55 });
56 56
57 - tearDownAll(() { 57 + tearDownAll(() async {
58 final file = File('widgets-partitions.pdf'); 58 final file = File('widgets-partitions.pdf');
59 - file.writeAsBytesSync(pdf.save()); 59 + await file.writeAsBytes(await pdf.save());
60 }); 60 });
61 } 61 }
@@ -110,8 +110,8 @@ void main() { @@ -110,8 +110,8 @@ void main() {
110 ); 110 );
111 }); 111 });
112 112
113 - tearDownAll(() { 113 + tearDownAll(() async {
114 final file = File('widgets-svg.pdf'); 114 final file = File('widgets-svg.pdf');
115 - file.writeAsBytesSync(pdf.save()); 115 + await file.writeAsBytes(await pdf.save());
116 }); 116 });
117 } 117 }
@@ -269,8 +269,8 @@ void main() { @@ -269,8 +269,8 @@ void main() {
269 ); 269 );
270 }); 270 });
271 271
272 - tearDownAll(() { 272 + tearDownAll(() async {
273 final file = File('widgets-table.pdf'); 273 final file = File('widgets-table.pdf');
274 - file.writeAsBytesSync(pdf.save()); 274 + await file.writeAsBytes(await pdf.save());
275 }); 275 });
276 } 276 }
@@ -279,8 +279,8 @@ void main() { @@ -279,8 +279,8 @@ void main() {
279 }, 279 },
280 ); 280 );
281 281
282 - tearDownAll(() { 282 + tearDownAll(() async {
283 final file = File('widgets.pdf'); 283 final file = File('widgets.pdf');
284 - file.writeAsBytesSync(pdf.save()); 284 + await file.writeAsBytes(await pdf.save());
285 }); 285 });
286 } 286 }
@@ -290,8 +290,8 @@ void main() { @@ -290,8 +290,8 @@ void main() {
290 ); 290 );
291 }); 291 });
292 292
293 - tearDownAll(() { 293 + tearDownAll(() async {
294 final file = File('widgets-text.pdf'); 294 final file = File('widgets-text.pdf');
295 - file.writeAsBytesSync(pdf.save()); 295 + await file.writeAsBytes(await pdf.save());
296 }); 296 });
297 } 297 }
@@ -126,8 +126,8 @@ void main() { @@ -126,8 +126,8 @@ void main() {
126 })); 126 }));
127 }); 127 });
128 128
129 - tearDownAll(() { 129 + tearDownAll(() async {
130 final file = File('widgets-theme.pdf'); 130 final file = File('widgets-theme.pdf');
131 - file.writeAsBytesSync(pdf.save()); 131 + await file.writeAsBytes(await pdf.save());
132 }); 132 });
133 } 133 }
@@ -100,8 +100,8 @@ void main() { @@ -100,8 +100,8 @@ void main() {
100 ); 100 );
101 }); 101 });
102 102
103 - tearDownAll(() { 103 + tearDownAll(() async {
104 final file = File('widgets-watermark.pdf'); 104 final file = File('widgets-watermark.pdf');
105 - file.writeAsBytesSync(pdf.save()); 105 + await file.writeAsBytes(await pdf.save());
106 }); 106 });
107 } 107 }
@@ -315,8 +315,8 @@ void main() { @@ -315,8 +315,8 @@ void main() {
315 ); 315 );
316 }); 316 });
317 317
318 - tearDownAll(() { 318 + tearDownAll(() async {
319 final file = File('widgets-wrap.pdf'); 319 final file = File('widgets-wrap.pdf');
320 - file.writeAsBytesSync(pdf.save()); 320 + await file.writeAsBytes(await pdf.save());
321 }); 321 });
322 } 322 }
1 # Changelog 1 # Changelog
2 2
  3 +## 4.0.0
  4 +
  5 +- Remove deprecated methods
  6 +- Document.save() now returns a Future
  7 +
3 ## 3.7.2 8 ## 3.7.2
4 9
5 - Fix Printing on WEB 10 - Fix Printing on WEB
@@ -84,7 +84,7 @@ To save the pdf file using the [path_provider](https://pub.dev/packages/path_pro @@ -84,7 +84,7 @@ To save the pdf file using the [path_provider](https://pub.dev/packages/path_pro
84 ```dart 84 ```dart
85 final output = await getTemporaryDirectory(); 85 final output = await getTemporaryDirectory();
86 final file = File("${output.path}/example.pdf"); 86 final file = File("${output.path}/example.pdf");
87 -await file.writeAsBytes(doc.save()); 87 +await file.writeAsBytes(await doc.save());
88 ``` 88 ```
89 89
90 You can also print the document using the iOS or Android print service: 90 You can also print the document using the iOS or Android print service:
@@ -97,7 +97,7 @@ await Printing.layoutPdf( @@ -97,7 +97,7 @@ await Printing.layoutPdf(
97 Or share the document to other applications: 97 Or share the document to other applications:
98 98
99 ```dart 99 ```dart
100 -await Printing.sharePdf(bytes: doc.save(), filename: 'my-document.pdf'); 100 +await Printing.sharePdf(bytes: await doc.save(), filename: 'my-document.pdf');
101 ``` 101 ```
102 102
103 To print an HTML document: 103 To print an HTML document:
@@ -113,7 +113,7 @@ await Printing.layoutPdf( @@ -113,7 +113,7 @@ await Printing.layoutPdf(
113 Convert a Pdf to images, one image per page, get only pages 1 and 2 at 72 dpi: 113 Convert a Pdf to images, one image per page, get only pages 1 and 2 at 72 dpi:
114 114
115 ```dart 115 ```dart
116 -await for (var page in Printing.raster(doc.save(), pages: [0, 1], dpi: 72)) { 116 +await for (var page in Printing.raster(await doc.save(), pages: [0, 1], dpi: 72)) {
117 final image = page.toImage(); // ...or page.toPng() 117 final image = page.toImage(); // ...or page.toPng()
118 print(image); 118 print(image);
119 } 119 }
@@ -126,19 +126,13 @@ mixin Printing { @@ -126,19 +126,13 @@ mixin Printing {
126 126
127 /// Displays a platform popup to share the Pdf document to another application 127 /// Displays a platform popup to share the Pdf document to another application
128 static Future<bool> sharePdf({ 128 static Future<bool> sharePdf({
129 - @Deprecated('use bytes with document.save()') PdfDocument document,  
130 - Uint8List bytes, 129 + @required Uint8List bytes,
131 String filename = 'document.pdf', 130 String filename = 'document.pdf',
132 Rect bounds, 131 Rect bounds,
133 }) { 132 }) {
134 - assert(document != null || bytes != null);  
135 - assert(!(document == null && bytes == null)); 133 + assert(bytes != null);
136 assert(filename != null); 134 assert(filename != null);
137 135
138 - if (document != null) {  
139 - bytes = document.save();  
140 - }  
141 -  
142 bounds ??= Rect.fromCircle(center: Offset.zero, radius: 10); 136 bounds ??= Rect.fromCircle(center: Offset.zero, radius: 10);
143 137
144 return PrintingPlatform.instance.sharePdf( 138 return PrintingPlatform.instance.sharePdf(
@@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to
4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing 4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
5 repository: https://github.com/DavBfr/dart_pdf 5 repository: https://github.com/DavBfr/dart_pdf
6 issue_tracker: https://github.com/DavBfr/dart_pdf/issues 6 issue_tracker: https://github.com/DavBfr/dart_pdf/issues
7 -version: 3.7.2 7 +version: 4.0.0
8 8
9 environment: 9 environment:
10 sdk: ">=2.3.0 <3.0.0" 10 sdk: ">=2.3.0 <3.0.0"
@@ -18,7 +18,7 @@ dependencies: @@ -18,7 +18,7 @@ dependencies:
18 image: ^2.1.4 18 image: ^2.1.4
19 js: ^0.6.1 19 js: ^0.6.1
20 meta: ^1.1.5 20 meta: ^1.1.5
21 - pdf: ^1.13.0 21 + pdf: ^2.0.0
22 plugin_platform_interface: ^1.0.2 22 plugin_platform_interface: ^1.0.2
23 23
24 dev_dependencies: 24 dev_dependencies:
@@ -68,8 +68,8 @@ void main() { @@ -68,8 +68,8 @@ void main() {
68 doc = pw.Document(); 68 doc = pw.Document();
69 }); 69 });
70 70
71 - tearDownAll(() { 71 + tearDownAll(() async {
72 final file = File('printing.pdf'); 72 final file = File('printing.pdf');
73 - file.writeAsBytesSync(doc.save()); 73 + await file.writeAsBytes(await doc.save());
74 }); 74 });
75 } 75 }
@@ -7,7 +7,7 @@ import 'package:string_scanner/string_scanner.dart'; @@ -7,7 +7,7 @@ import 'package:string_scanner/string_scanner.dart';
7 const dpi = 72.0; 7 const dpi = 72.0;
8 const px = dpi / PdfPageFormat.inch * PdfPageFormat.point; 8 const px = dpi / PdfPageFormat.inch * PdfPageFormat.point;
9 9
10 -void main() { 10 +Future<void> main() async {
11 // Open self 11 // Open self
12 final source = File('../test/github_social_preview.dart').readAsStringSync(); 12 final source = File('../test/github_social_preview.dart').readAsStringSync();
13 final code = DartSyntaxHighlighter( 13 final code = DartSyntaxHighlighter(
@@ -74,7 +74,7 @@ void main() { @@ -74,7 +74,7 @@ void main() {
74 // END 74 // END
75 75
76 // Save the file 76 // Save the file
77 - File('social_preview.pdf').writeAsBytesSync(pdf.save()); 77 + await File('social_preview.pdf').writeAsBytes(await pdf.save());
78 78
79 // Convert to png 79 // Convert to png
80 Process.runSync('pdftocairo', 80 Process.runSync('pdftocairo',