David PHAM-VAN

Default compress output if available

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 * Add encryption support 4 * Add encryption support
5 * Increase PDF version to 1.7 5 * Increase PDF version to 1.7
6 * Add document signature support 6 * Add document signature support
  7 +* Default compress output if available
7 8
8 ## 1.3.13 9 ## 1.3.13
9 10
@@ -4,7 +4,7 @@ import 'package:pdf/pdf.dart'; @@ -4,7 +4,7 @@ import 'package:pdf/pdf.dart';
4 import 'package:pdf/widgets.dart'; 4 import 'package:pdf/widgets.dart';
5 5
6 void main() { 6 void main() {
7 - final Document pdf = Document(deflate: zlib.encode); 7 + final Document pdf = Document();
8 8
9 pdf.addPage(MultiPage( 9 pdf.addPage(MultiPage(
10 pageFormat: 10 pageFormat:
@@ -26,6 +26,8 @@ import 'package:meta/meta.dart'; @@ -26,6 +26,8 @@ import 'package:meta/meta.dart';
26 import 'package:utf/utf.dart'; 26 import 'package:utf/utf.dart';
27 import 'package:vector_math/vector_math_64.dart'; 27 import 'package:vector_math/vector_math_64.dart';
28 28
  29 +import 'src/io.dart' if (dart.library.io) 'src/archive.dart';
  30 +
29 part 'src/annotation.dart'; 31 part 'src/annotation.dart';
30 part 'src/array.dart'; 32 part 'src/array.dart';
31 part 'src/ascii85.dart'; 33 part 'src/ascii85.dart';
  1 +import 'package:archive/archive.dart';
  2 +
  3 +import 'package:pdf/pdf.dart';
  4 +
  5 +DeflateCallback defaultDeflate = ZLibEncoder().encode;
@@ -46,7 +46,11 @@ class PdfDocument { @@ -46,7 +46,11 @@ class PdfDocument {
46 /// This creates a Pdf document 46 /// This creates a Pdf document
47 /// @param pagemode an int, determines how the document will present itself to 47 /// @param pagemode an int, determines how the document will present itself to
48 /// the viewer when it first opens. 48 /// the viewer when it first opens.
49 - PdfDocument({PdfPageMode pageMode = PdfPageMode.none, this.deflate}) { 49 + PdfDocument({
  50 + PdfPageMode pageMode = PdfPageMode.none,
  51 + DeflateCallback deflate,
  52 + bool compress = true,
  53 + }) : deflate = compress ? (deflate ?? defaultDeflate) : null {
50 _objser = 1; 54 _objser = 1;
51 55
52 // Now create some standard objects 56 // Now create some standard objects
  1 +import 'dart:io';
  2 +
  3 +import 'package:pdf/pdf.dart';
  4 +
  5 +DeflateCallback defaultDeflate = zlib.encode;
@@ -20,6 +20,7 @@ class Document { @@ -20,6 +20,7 @@ class Document {
20 Document( 20 Document(
21 {PdfPageMode pageMode = PdfPageMode.none, 21 {PdfPageMode pageMode = PdfPageMode.none,
22 DeflateCallback deflate, 22 DeflateCallback deflate,
  23 + bool compress = true,
23 this.theme, 24 this.theme,
24 String title, 25 String title,
25 String author, 26 String author,
@@ -27,7 +28,11 @@ class Document { @@ -27,7 +28,11 @@ class Document {
27 String subject, 28 String subject,
28 String keywords, 29 String keywords,
29 String producer}) 30 String producer})
30 - : document = PdfDocument(pageMode: pageMode, deflate: deflate) { 31 + : document = PdfDocument(
  32 + pageMode: pageMode,
  33 + deflate: deflate,
  34 + compress: compress,
  35 + ) {
31 if (title != null || 36 if (title != null ||
32 author != null || 37 author != null ||
33 creator != null || 38 creator != null ||
@@ -14,6 +14,7 @@ dependencies: @@ -14,6 +14,7 @@ dependencies:
14 vector_math: "^2.0.0" 14 vector_math: "^2.0.0"
15 utf: "^0.9.0" 15 utf: "^0.9.0"
16 crypto: "^2.0.6" 16 crypto: "^2.0.6"
  17 + archive: "^2.0.10"
17 18
18 dev_dependencies: 19 dev_dependencies:
19 test: any 20 test: any
@@ -14,7 +14,7 @@ for documentation. @@ -14,7 +14,7 @@ for documentation.
14 Example: 14 Example:
15 15
16 ```dart 16 ```dart
17 -final pdf = PdfDoc(); 17 +final pdf = Document();
18 18
19 pdf.addPage(Page( 19 pdf.addPage(Page(
20 pageFormat: PdfPageFormat.a4, 20 pageFormat: PdfPageFormat.a4,
@@ -34,7 +34,7 @@ class MyApp extends StatelessWidget { @@ -34,7 +34,7 @@ class MyApp extends StatelessWidget {
34 } 34 }
35 35
36 List<int> buildPdf(PdfPageFormat format) { 36 List<int> buildPdf(PdfPageFormat format) {
37 - final PdfDoc doc = PdfDoc(); 37 + final Document doc = Document();
38 38
39 doc.addPage( 39 doc.addPage(
40 pdf.Page( 40 pdf.Page(
@@ -107,7 +107,7 @@ class Category extends StatelessWidget { @@ -107,7 +107,7 @@ class Category extends StatelessWidget {
107 } 107 }
108 108
109 Future<Document> generateDocument(PdfPageFormat format) async { 109 Future<Document> generateDocument(PdfPageFormat format) async {
110 - final PdfDoc pdf = PdfDoc(title: 'My Résumé', author: 'David PHAM-VAN'); 110 + final Document pdf = Document(title: 'My Résumé', author: 'David PHAM-VAN');
111 111
112 final PdfImage profileImage = await pdfImageFromImageProvider( 112 final PdfImage profileImage = await pdfImageFromImageProvider(
113 pdf: pdf.document, 113 pdf: pdf.document,
@@ -74,7 +74,7 @@ class MyAppState extends State<MyApp> { @@ -74,7 +74,7 @@ class MyAppState extends State<MyApp> {
74 print('Print Screen ${im.width}x${im.height} ...'); 74 print('Print Screen ${im.width}x${im.height} ...');
75 75
76 Printing.layoutPdf(onLayout: (PdfPageFormat format) { 76 Printing.layoutPdf(onLayout: (PdfPageFormat format) {
77 - final pdf.Document document = PdfDoc(); 77 + final pdf.Document document = pdf.Document();
78 78
79 final PdfImage image = PdfImage(document.document, 79 final PdfImage image = PdfImage(document.document,
80 image: bytes.buffer.asUint8List(), 80 image: bytes.buffer.asUint8List(),
@@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
17 library printing; 17 library printing;
18 18
19 import 'dart:async'; 19 import 'dart:async';
20 -import 'dart:io';  
21 import 'dart:typed_data'; 20 import 'dart:typed_data';
22 import 'dart:ui' as ui; 21 import 'dart:ui' as ui;
23 22
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of printing; 17 part of printing;
18 18
  19 +@deprecated
19 class PdfDoc extends Document { 20 class PdfDoc extends Document {
20 /// Wrapper for a [Document] with zlib compression enabled by default 21 /// Wrapper for a [Document] with zlib compression enabled by default
21 PdfDoc( 22 PdfDoc(
@@ -29,7 +30,7 @@ class PdfDoc extends Document { @@ -29,7 +30,7 @@ class PdfDoc extends Document {
29 String keywords, 30 String keywords,
30 String producer}) 31 String producer})
31 : super( 32 : super(
32 - deflate: compress ? zlib.encode : null, 33 + compress: compress,
33 pageMode: pageMode, 34 pageMode: pageMode,
34 theme: theme, 35 theme: theme,
35 title: title, 36 title: title,