David PHAM-VAN

Remove dependency to dart:io for web

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