Showing
3 changed files
with
7 additions
and
4 deletions
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | - Improve PdfArray and PdfDict constructors | 7 | - Improve PdfArray and PdfDict constructors |
| 8 | - Fix underline on spans [RomanIvn] | 8 | - Fix underline on spans [RomanIvn] |
| 9 | - Improve verbose output | 9 | - Improve verbose output |
| 10 | +- Allow saving an unmodified document | ||
| 10 | 11 | ||
| 11 | ## 3.10.1 | 12 | ## 3.10.1 |
| 12 | 13 |
| @@ -219,7 +219,7 @@ class PdfDocument { | @@ -219,7 +219,7 @@ class PdfDocument { | ||
| 219 | Future<void> _write(PdfStream os) async { | 219 | Future<void> _write(PdfStream os) async { |
| 220 | PdfSignature? signature; | 220 | PdfSignature? signature; |
| 221 | 221 | ||
| 222 | - final xref = PdfXrefTable(); | 222 | + final xref = PdfXrefTable(lastObjectId: _objser); |
| 223 | 223 | ||
| 224 | for (final ob in objects.where((e) => e.inUse)) { | 224 | for (final ob in objects.where((e) => e.inUse)) { |
| 225 | ob.prepare(); | 225 | ob.prepare(); |
| @@ -91,7 +91,7 @@ class PdfXref extends PdfIndirect { | @@ -91,7 +91,7 @@ class PdfXref extends PdfIndirect { | ||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | class PdfXrefTable extends PdfDataType with PdfDiagnostic { | 93 | class PdfXrefTable extends PdfDataType with PdfDiagnostic { |
| 94 | - PdfXrefTable(); | 94 | + PdfXrefTable({this.lastObjectId = 0}); |
| 95 | 95 | ||
| 96 | /// Document root point | 96 | /// Document root point |
| 97 | final params = PdfDict(); | 97 | final params = PdfDict(); |
| @@ -99,6 +99,8 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | @@ -99,6 +99,8 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | ||
| 99 | /// List of objects to write | 99 | /// List of objects to write |
| 100 | final objects = <PdfObjectBase>{}; | 100 | final objects = <PdfObjectBase>{}; |
| 101 | 101 | ||
| 102 | + final int lastObjectId; | ||
| 103 | + | ||
| 102 | /// Writes a block of references to the Pdf file | 104 | /// Writes a block of references to the Pdf file |
| 103 | void _writeBlock(PdfStream s, int firstId, List<PdfXref> block) { | 105 | void _writeBlock(PdfStream s, int firstId, List<PdfXref> block) { |
| 104 | s.putString('$firstId ${block.length}\n'); | 106 | s.putString('$firstId ${block.length}\n'); |
| @@ -192,7 +194,7 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | @@ -192,7 +194,7 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | ||
| 192 | int _outputLegacy(PdfObjectBase o, PdfStream s, List<PdfXref> xrefList) { | 194 | int _outputLegacy(PdfObjectBase o, PdfStream s, List<PdfXref> xrefList) { |
| 193 | // Now scan through the offsets list. They should be in sequence. | 195 | // Now scan through the offsets list. They should be in sequence. |
| 194 | xrefList.sort((a, b) => a.ser.compareTo(b.ser)); | 196 | xrefList.sort((a, b) => a.ser.compareTo(b.ser)); |
| 195 | - final size = xrefList.last.ser + 1; | 197 | + final size = math.max(lastObjectId, xrefList.last.ser + 1); |
| 196 | 198 | ||
| 197 | var firstId = 0; // First id in block | 199 | var firstId = 0; // First id in block |
| 198 | var lastId = 0; // The last id used | 200 | var lastId = 0; // The last id used |
| @@ -249,7 +251,7 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | @@ -249,7 +251,7 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic { | ||
| 249 | xrefList.sort((a, b) => a.ser.compareTo(b.ser)); | 251 | xrefList.sort((a, b) => a.ser.compareTo(b.ser)); |
| 250 | 252 | ||
| 251 | // Write this object too | 253 | // Write this object too |
| 252 | - final id = xrefList.last.ser + 1; | 254 | + final id = math.max(lastObjectId, xrefList.last.ser + 1); |
| 253 | final size = id + 1; | 255 | final size = id + 1; |
| 254 | xrefList.add(PdfXref(id, offset)); | 256 | xrefList.add(PdfXref(id, offset)); |
| 255 | 257 |
-
Please register or login to post a comment