David PHAM-VAN

Fix MultiPage with multiple save() calls

1 # Changelog 1 # Changelog
2 2
  3 +## 1.3.17
  4 +
  5 +* Fix MultiPage with multiple save() calls
  6 +
3 ## 1.3.16 7 ## 1.3.16
4 8
5 * Add better debugPaint on Align Widget 9 * Add better debugPaint on Align Widget
@@ -39,7 +39,7 @@ class PdfObjectStream extends PdfObject { @@ -39,7 +39,7 @@ class PdfObjectStream extends PdfObject {
39 void _prepare() { 39 void _prepare() {
40 super._prepare(); 40 super._prepare();
41 41
42 - if (params.containsKey('/Filter')) { 42 + if (params.containsKey('/Filter') && _data == null) {
43 // The data is already in the right format 43 // The data is already in the right format
44 _data = buf.output(); 44 _data = buf.output();
45 } else if (pdfDocument.deflate != null) { 45 } else if (pdfDocument.deflate != null) {
@@ -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.3.16 7 +version: 1.3.17
8 8
9 environment: 9 environment:
10 sdk: ">=2.1.0 <3.0.0" 10 sdk: ">=2.1.0 <3.0.0"
@@ -28,6 +28,7 @@ import 'type1_test.dart' as type1; @@ -28,6 +28,7 @@ import 'type1_test.dart' as type1;
28 import 'widget_basic_test.dart' as widget_basic; 28 import 'widget_basic_test.dart' as widget_basic;
29 import 'widget_clip_test.dart' as widget_clip; 29 import 'widget_clip_test.dart' as widget_clip;
30 import 'widget_container_test.dart' as widget_container; 30 import 'widget_container_test.dart' as widget_container;
  31 +import 'widget_multipage_test.dart' as widget_multipage;
31 import 'widget_table_test.dart' as widget_table; 32 import 'widget_table_test.dart' as widget_table;
32 import 'widget_test.dart' as widget; 33 import 'widget_test.dart' as widget;
33 import 'widget_text_test.dart' as widget_text; 34 import 'widget_text_test.dart' as widget_text;
@@ -47,6 +48,7 @@ void main() { @@ -47,6 +48,7 @@ void main() {
47 widget_basic.main(); 48 widget_basic.main();
48 widget_clip.main(); 49 widget_clip.main();
49 widget_container.main(); 50 widget_container.main();
  51 + widget_multipage.main();
50 widget_table.main(); 52 widget_table.main();
51 widget_text.main(); 53 widget_text.main();
52 widget_theme.main(); 54 widget_theme.main();
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +import 'dart:io';
  18 +
  19 +import 'package:pdf/widgets.dart';
  20 +import 'package:test/test.dart';
  21 +
  22 +List<Widget> lines = <Widget>[];
  23 +
  24 +void main() {
  25 + setUpAll(() {
  26 + for (int i = 0; i < 200; i++) {
  27 + lines.add(Text('Line $i'));
  28 + }
  29 + });
  30 +
  31 + test('Pdf Widgets MultiPage', () {
  32 + Document.debug = true;
  33 +
  34 + final Document pdf = Document();
  35 +
  36 + pdf.addPage(MultiPage(build: (Context context) => lines));
  37 +
  38 + final File file = File('widgets-multipage.pdf');
  39 + file.writeAsBytesSync(pdf.save());
  40 +
  41 + final File file1 = File('widgets-multipage-1.pdf');
  42 + file1.writeAsBytesSync(pdf.save());
  43 + });
  44 +
  45 + test('Pdf Widgets MonoPage', () {
  46 + Document.debug = true;
  47 +
  48 + final Document pdf = Document();
  49 +
  50 + pdf.addPage(Page(build: (Context context) => Column(children: lines)));
  51 +
  52 + final File file = File('widgets-monopage.pdf');
  53 + file.writeAsBytesSync(pdf.save());
  54 +
  55 + final File file1 = File('widgets-monopage-1.pdf');
  56 + file1.writeAsBytesSync(pdf.save());
  57 + });
  58 +}