David PHAM-VAN

Remove dependency to dart:io for web

  1 +# 1.0.5
  2 +* Remove dependency to dart:io
  3 +* Add Contributing
  4 +
1 # 1.0.4 5 # 1.0.4
2 * Updated homepage 6 * Updated homepage
3 * Update source formatting 7 * Update source formatting
@@ -3,7 +3,7 @@ import 'dart:io'; @@ -3,7 +3,7 @@ import 'dart:io';
3 import 'package:pdf/pdf.dart'; 3 import 'package:pdf/pdf.dart';
4 4
5 void main() { 5 void main() {
6 - final pdf = new PDFDocument(); 6 + final pdf = new PDFDocument(deflate: zlib.encode);
7 final page = new PDFPage(pdf, pageFormat: PDFPageFormat.LETTER); 7 final page = new PDFPage(pdf, pageFormat: PDFPageFormat.LETTER);
8 final g = page.getGraphics(); 8 final g = page.getGraphics();
9 final font = new PDFFont(pdf); 9 final font = new PDFFont(pdf);
@@ -19,7 +19,6 @@ @@ -19,7 +19,6 @@
19 library pdf; 19 library pdf;
20 20
21 import 'dart:convert'; 21 import 'dart:convert';
22 -import 'dart:io';  
23 import 'dart:typed_data'; 22 import 'dart:typed_data';
24 23
25 import 'package:meta/meta.dart'; 24 import 'package:meta/meta.dart';
@@ -18,8 +18,8 @@ @@ -18,8 +18,8 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class Ascii85Encoder extends Converter<Uint8List, Uint8List> {  
22 - Uint8List convert(Uint8List input) { 21 +class Ascii85Encoder extends Converter<List<int>, List<int>> {
  22 + List<int> convert(List<int> input) {
23 Uint8List buffer = new Uint8List(_maxEncodedLen(input.length) + 2); 23 Uint8List buffer = new Uint8List(_maxEncodedLen(input.length) + 2);
24 24
25 var b = 0; 25 var b = 0;
@@ -37,6 +37,8 @@ enum PDFPageMode { @@ -37,6 +37,8 @@ enum PDFPageMode {
37 FULLSCREEN 37 FULLSCREEN
38 } 38 }
39 39
  40 +typedef List<int> DeflateCallback(List<int> data);
  41 +
40 /// <p>This class is the base of the PDF generator. A PDFDocument class is 42 /// <p>This class is the base of the PDF generator. A PDFDocument class is
41 /// created for a document, and each page, object, annotation, 43 /// created for a document, and each page, object, annotation,
42 /// etc is added to the document. 44 /// etc is added to the document.
@@ -66,8 +68,10 @@ class PDFDocument { @@ -66,8 +68,10 @@ class PDFDocument {
66 /// It's only used when the document is being written. 68 /// It's only used when the document is being written.
67 PDFObject defaultOutlineBorder; 69 PDFObject defaultOutlineBorder;
68 70
69 - /// True if we will compress the stream in the pdf file  
70 - final bool deflate; 71 + /// Callback to compress the stream in the pdf file.
  72 + /// Use `deflate: zlib.encode` if using dart:io
  73 + /// No compression by default
  74 + final DeflateCallback deflate;
71 75
72 /// <p> 76 /// <p>
73 /// These map the page modes just defined to the pagemodes setting of PDF. 77 /// These map the page modes just defined to the pagemodes setting of PDF.
@@ -88,7 +92,7 @@ class PDFDocument { @@ -88,7 +92,7 @@ class PDFDocument {
88 /// <p>This creates a PDF document</p> 92 /// <p>This creates a PDF document</p>
89 /// @param pagemode an int, determines how the document will present itself to 93 /// @param pagemode an int, determines how the document will present itself to
90 /// the viewer when it first opens. 94 /// the viewer when it first opens.
91 - PDFDocument({PDFPageMode pageMode = PDFPageMode.NONE, this.deflate = true}) { 95 + PDFDocument({PDFPageMode pageMode = PDFPageMode.NONE, this.deflate}) {
92 _objser = 1; 96 _objser = 1;
93 97
94 // Now create some standard objects 98 // Now create some standard objects
@@ -141,7 +145,7 @@ class PDFDocument { @@ -141,7 +145,7 @@ class PDFDocument {
141 pos.close(); 145 pos.close();
142 } 146 }
143 147
144 - Uint8List save() { 148 + List<int> save() {
145 PDFStream os = new PDFStream(); 149 PDFStream os = new PDFStream();
146 write(os); 150 write(os);
147 return os.output(); 151 return os.output();
@@ -34,15 +34,14 @@ class PDFObjectStream extends PDFObject { @@ -34,15 +34,14 @@ class PDFObjectStream extends PDFObject {
34 PDFObjectStream(PDFDocument pdfDocument, {String type, this.isBinary = false}) 34 PDFObjectStream(PDFDocument pdfDocument, {String type, this.isBinary = false})
35 : super(pdfDocument, type); 35 : super(pdfDocument, type);
36 36
37 - Uint8List _data; 37 + List<int> _data;
38 38
39 @override 39 @override
40 void prepare() { 40 void prepare() {
41 super.prepare(); 41 super.prepare();
42 42
43 - if (pdfDocument.deflate) {  
44 - var z = new ZLibCodec(level: ZLibOption.maxLevel);  
45 - _data = z.encode(buf.output()); 43 + if (pdfDocument.deflate != null) {
  44 + _data = pdfDocument.deflate(buf.output());
46 params["/Filter"] = PDFStream.string("/FlateDecode"); 45 params["/Filter"] = PDFStream.string("/FlateDecode");
47 } else if (isBinary) { 46 } else if (isBinary) {
48 // This is a Ascii85 stream 47 // This is a Ascii85 stream
@@ -19,18 +19,18 @@ @@ -19,18 +19,18 @@
19 part of pdf; 19 part of pdf;
20 20
21 class PDFStream { 21 class PDFStream {
22 - final _stream = new BytesBuilder(copy: false); 22 + final _stream = List<int>();
23 23
24 void putStream(PDFStream s) { 24 void putStream(PDFStream s) {
25 - _stream.add(s._stream.toBytes()); 25 + _stream.addAll(s._stream);
26 } 26 }
27 27
28 void putString(String s) { 28 void putString(String s) {
29 for (int codeUnit in s.codeUnits) { 29 for (int codeUnit in s.codeUnits) {
30 if (codeUnit <= 0x7f) { 30 if (codeUnit <= 0x7f) {
31 - _stream.addByte(codeUnit); 31 + _stream.add(codeUnit);
32 } else { 32 } else {
33 - _stream.addByte(0x20); 33 + _stream.add(0x20);
34 } 34 }
35 } 35 }
36 } 36 }
@@ -39,13 +39,13 @@ class PDFStream { @@ -39,13 +39,13 @@ class PDFStream {
39 39
40 void putStringUtf16(String s) { 40 void putStringUtf16(String s) {
41 for (int codeUnit in s.codeUnits) { 41 for (int codeUnit in s.codeUnits) {
42 - _stream.addByte(codeUnit & 0xff);  
43 - _stream.addByte((codeUnit >> 8) & 0xff); 42 + _stream.add(codeUnit & 0xff);
  43 + _stream.add((codeUnit >> 8) & 0xff);
44 } 44 }
45 } 45 }
46 46
47 void putBytes(List<int> s) { 47 void putBytes(List<int> s) {
48 - _stream.add(s); 48 + _stream.addAll(s);
49 } 49 }
50 50
51 void putNum(double d) { 51 void putNum(double d) {
@@ -135,5 +135,5 @@ class PDFStream { @@ -135,5 +135,5 @@ class PDFStream {
135 135
136 int get offset => _stream.length; 136 int get offset => _stream.length;
137 137
138 - Uint8List output() => _stream.toBytes(); 138 + List<int> output() => _stream;
139 } 139 }
@@ -2,7 +2,7 @@ name: pdf @@ -2,7 +2,7 @@ name: pdf
2 author: David PHAM-VAN <dev.nfet.net@gmail.com> 2 author: David PHAM-VAN <dev.nfet.net@gmail.com>
3 description: A pdf producer for Dart. It can create pdf files for both web or flutter. 3 description: A pdf producer for Dart. It can create pdf files for both web or flutter.
4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf 4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
5 -version: 1.0.4 5 +version: 1.0.5
6 6
7 environment: 7 environment:
8 sdk: ">=1.8.0 <3.0.0" 8 sdk: ">=1.8.0 <3.0.0"
@@ -8,10 +8,11 @@ import 'package:vector_math/vector_math_64.dart'; @@ -8,10 +8,11 @@ import 'package:vector_math/vector_math_64.dart';
8 8
9 void main() { 9 void main() {
10 test('Pdf', () { 10 test('Pdf', () {
11 -// Image img = new Image(10, 10);  
12 -// img.fill(0x12345678); 11 + var img = new Uint32List(10 * 10);
  12 + print(img.length);
  13 + img.fillRange(0, img.length - 1, 0x12345678);
13 14
14 - var pdf = new PDFDocument(deflate: false); 15 + var pdf = new PDFDocument(deflate: zlib.encode);
15 var i = pdf.info; 16 var i = pdf.info;
16 i.author = "David PHAM-VAN"; 17 i.author = "David PHAM-VAN";
17 i.creator = i.author; 18 i.creator = i.author;
@@ -50,8 +51,8 @@ void main() { @@ -50,8 +51,8 @@ void main() {
50 g.drawRect(300.0, 150.0, 50.0, 50.0); 51 g.drawRect(300.0, 150.0, 50.0, 50.0);
51 g.fillPath(); 52 g.fillPath();
52 g.setColor(new PDFColor(0.0, 0.5, 0.0)); 53 g.setColor(new PDFColor(0.0, 0.5, 0.0));
53 -// var image = new PDFImage(pdf,  
54 -// image: img.data.buffer.asUint8List(), width: img.width, height: img.height); 54 + var image = new PDFImage(pdf,
  55 + image: img.buffer.asUint8List(), width: 10, height: 10);
55 for (var i = 10.0; i < 90.0; i += 5.0) { 56 for (var i = 10.0; i < 90.0; i += 5.0) {
56 g.saveContext(); 57 g.saveContext();
57 var tm = new Matrix4.identity(); 58 var tm = new Matrix4.identity();
@@ -59,7 +60,7 @@ void main() { @@ -59,7 +60,7 @@ void main() {
59 tm.translate(300.0, -100.0); 60 tm.translate(300.0, -100.0);
60 g.setTransform(tm); 61 g.setTransform(tm);
61 g.drawString(font1, 12.0, "Hello $i", 20.0, 100.0); 62 g.drawString(font1, 12.0, "Hello $i", 20.0, 100.0);
62 -// g.drawImage(image, 100.0, 100.0, 80.0); 63 + g.drawImage(image, 100.0, 100.0);
63 g.restoreContext(); 64 g.restoreContext();
64 } 65 }
65 66
@@ -5,7 +5,7 @@ import "package:test/test.dart"; @@ -5,7 +5,7 @@ import "package:test/test.dart";
5 5
6 void main() { 6 void main() {
7 test('Pdf1', () { 7 test('Pdf1', () {
8 - var pdf = new PDFDocument(deflate: false); 8 + var pdf = new PDFDocument();
9 var page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4); 9 var page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4);
10 10
11 var g = page.getGraphics(); 11 var g = page.getGraphics();
@@ -6,7 +6,7 @@ import 'package:test/test.dart'; @@ -6,7 +6,7 @@ import 'package:test/test.dart';
6 6
7 void main() { 7 void main() {
8 test('Pdf', () { 8 test('Pdf', () {
9 - var pdf = new PDFDocument(deflate: false); 9 + var pdf = new PDFDocument();
10 var i = pdf.info; 10 var i = pdf.info;
11 i.author = "David PHAM-VAN"; 11 i.author = "David PHAM-VAN";
12 i.creator = i.author; 12 i.creator = i.author;
  1 +# 1.0.4
  2 +* Update example for pdf 1.0.5
  3 +* Add Contributing
  4 +
1 # 1.0.3 5 # 1.0.3
2 * Update source formatting 6 * Update source formatting
3 * Update README 7 * Update README
  1 +import 'dart:io';
1 import 'dart:ui'; 2 import 'dart:ui';
2 3
3 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
@@ -10,7 +11,7 @@ class MyApp extends StatelessWidget { @@ -10,7 +11,7 @@ class MyApp extends StatelessWidget {
10 final shareWidget = new GlobalKey(); 11 final shareWidget = new GlobalKey();
11 12
12 PDFDocument _generateDocument() { 13 PDFDocument _generateDocument() {
13 - final pdf = new PDFDocument(); 14 + final pdf = new PDFDocument(deflate: zlib.encode);
14 final page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4); 15 final page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4);
15 final g = page.getGraphics(); 16 final g = page.getGraphics();
16 final font = new PDFFont(pdf); 17 final font = new PDFFont(pdf);
@@ -2,7 +2,7 @@ name: printing @@ -2,7 +2,7 @@ name: printing
2 author: David PHAM-VAN <dev.nfet.net@gmail.com> 2 author: David PHAM-VAN <dev.nfet.net@gmail.com>
3 description: Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers 3 description: Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing 4 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
5 -version: 1.0.3 5 +version: 1.0.4
6 6
7 environment: 7 environment:
8 sdk: ">=1.19.0 <3.0.0" 8 sdk: ">=1.19.0 <3.0.0"
@@ -10,7 +10,7 @@ environment: @@ -10,7 +10,7 @@ environment:
10 dependencies: 10 dependencies:
11 flutter: 11 flutter:
12 sdk: flutter 12 sdk: flutter
13 - pdf: "^1.0.3" 13 + pdf: "^1.0.5"
14 14
15 flutter: 15 flutter:
16 plugin: 16 plugin: