David PHAM-VAN

Add support for deleted objects

@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 - Improve documentation strings 8 - Improve documentation strings
9 - Improve verbose output 9 - Improve verbose output
10 - Import already defined form 10 - Import already defined form
  11 +- Add support for deleted objects
11 12
12 ## 3.9.0 13 ## 3.9.0
13 14
@@ -35,6 +35,7 @@ import 'obj/page_list.dart'; @@ -35,6 +35,7 @@ import 'obj/page_list.dart';
35 import 'obj/signature.dart'; 35 import 'obj/signature.dart';
36 import 'output.dart'; 36 import 'output.dart';
37 import 'stream.dart'; 37 import 'stream.dart';
  38 +import 'xref.dart';
38 39
39 /// PDF version to generate 40 /// PDF version to generate
40 enum PdfVersion { 41 enum PdfVersion {
@@ -213,7 +214,17 @@ class PdfDocument { @@ -213,7 +214,17 @@ class PdfDocument {
213 214
214 // Write each object to the [PdfStream]. We call via the output 215 // Write each object to the [PdfStream]. We call via the output
215 // as that builds the xref table 216 // as that builds the xref table
216 - objects.forEach(pos.write); 217 + objects.where((e) => e.inUse).forEach(pos.write);
  218 + var lastFree = 0;
  219 + for (final obj in objects.where((e) => !e.inUse)) {
  220 + pos.xref.add(PdfXref(
  221 + obj.objser,
  222 + lastFree,
  223 + generation: obj.objgen,
  224 + type: PdfCrossRefEntryType.free,
  225 + ));
  226 + lastFree = obj.objser;
  227 + }
217 228
218 // Finally close the output, which writes the xref table. 229 // Finally close the output, which writes the xref table.
219 await pos.close(); 230 await pos.close();
@@ -46,6 +46,8 @@ abstract class PdfObject<T extends PdfDataType> with PdfDiagnostic { @@ -46,6 +46,8 @@ abstract class PdfObject<T extends PdfDataType> with PdfDiagnostic {
46 /// This allows any Pdf object to refer to the document being constructed. 46 /// This allows any Pdf object to refer to the document being constructed.
47 final PdfDocument pdfDocument; 47 final PdfDocument pdfDocument;
48 48
  49 + var inUse = true;
  50 +
49 /// Writes the object to the output stream. 51 /// Writes the object to the output stream.
50 void write(PdfStream os) { 52 void write(PdfStream os) {
51 prepare(); 53 prepare();