@syncfusion/ej2-pdf 25.1.35 → 25.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53173,31 +53173,45 @@ var PdfDocument = /** @__PURE__ @class */ (function () {
53173
53173
  pageDictionary.objId = pageReference.toString();
53174
53174
  pageDictionary.update('Parent', sectionReference);
53175
53175
  sectionDictionary.update('Kids', [pageReference]);
53176
- var lastPage = this.getPage(pageIndex === this.pageCount ? (pageIndex - 1) : pageIndex);
53177
- if (lastPage && lastPage._pageDictionary) {
53178
- var parentReference = lastPage._pageDictionary._get('Parent');
53179
- var parentDictionary = this._crossReference._fetch(parentReference);
53180
- if (parentDictionary && parentDictionary.has('Kids')) {
53181
- var kids = parentDictionary.get('Kids');
53182
- if (kids) {
53183
- if (pageIndex === this.pageCount) {
53184
- kids.push(sectionReference);
53185
- }
53186
- else {
53187
- var newKids_1 = [];
53188
- kids.forEach(function (entry) {
53189
- if (entry === lastPage._ref) {
53190
- newKids_1.push(sectionReference);
53191
- }
53192
- newKids_1.push(entry);
53193
- });
53194
- kids = newKids_1;
53195
- this._updatePageCache(pageIndex);
53176
+ if (this.pageCount === 0) {
53177
+ var parentReference = this._catalog._catalogDictionary._get('Pages');
53178
+ if (parentReference && this._catalog._topPagesDictionary) {
53179
+ this._catalog._topPagesDictionary.update('Kids', [sectionReference]);
53180
+ sectionDictionary.update('Parent', parentReference);
53181
+ }
53182
+ else {
53183
+ this._catalog._catalogDictionary.update('Pages', sectionReference);
53184
+ }
53185
+ this._pages = new Map();
53186
+ this._pageCount = 1;
53187
+ }
53188
+ else {
53189
+ var lastPage_1 = this.getPage(pageIndex === this.pageCount ? (pageIndex - 1) : pageIndex);
53190
+ if (lastPage_1 && lastPage_1._pageDictionary) {
53191
+ var parentReference = lastPage_1._pageDictionary._get('Parent');
53192
+ var parentDictionary = this._crossReference._fetch(parentReference);
53193
+ if (parentDictionary && parentDictionary.has('Kids')) {
53194
+ var kids = parentDictionary.get('Kids');
53195
+ if (kids) {
53196
+ if (pageIndex === this.pageCount) {
53197
+ kids.push(sectionReference);
53198
+ }
53199
+ else {
53200
+ var newKids_1 = [];
53201
+ kids.forEach(function (entry) {
53202
+ if (entry === lastPage_1._ref) {
53203
+ newKids_1.push(sectionReference);
53204
+ }
53205
+ newKids_1.push(entry);
53206
+ });
53207
+ kids = newKids_1;
53208
+ this._updatePageCache(pageIndex);
53209
+ }
53210
+ parentDictionary.update('Kids', kids);
53211
+ sectionDictionary.update('Parent', parentReference);
53212
+ this._updatePageCount(parentDictionary, 1);
53213
+ this._pageCount = this.pageCount + 1;
53196
53214
  }
53197
- parentDictionary.update('Kids', kids);
53198
- sectionDictionary.update('Parent', parentReference);
53199
- this._updatePageCount(parentDictionary, 1);
53200
- this._pageCount = this.pageCount + 1;
53201
53215
  }
53202
53216
  }
53203
53217
  }
@@ -53297,17 +53311,19 @@ var PdfDocument = /** @__PURE__ @class */ (function () {
53297
53311
  }
53298
53312
  };
53299
53313
  PdfDocument.prototype._removeParent = function (referenceToRemove, dictionary) {
53300
- var parentReference = dictionary._get('Parent');
53301
- var parentDictionary = this._crossReference._fetch(parentReference);
53302
- if (parentDictionary && parentDictionary.has('Kids')) {
53303
- var kids = parentDictionary.get('Kids');
53304
- if (kids.length === 1 && parentDictionary && parentDictionary.get('Type').name === 'Pages') {
53305
- this._removeParent(parentReference, parentDictionary);
53306
- }
53307
- else {
53308
- kids = kids.filter(function (item) { return item !== referenceToRemove; });
53309
- parentDictionary.update('Kids', kids);
53310
- this._updatePageCount(parentDictionary, -1);
53314
+ if (dictionary.has('Parent')) {
53315
+ var parentReference = dictionary._get('Parent');
53316
+ var parentDictionary = this._crossReference._fetch(parentReference);
53317
+ if (parentDictionary && parentDictionary.has('Kids')) {
53318
+ var kids = parentDictionary.get('Kids');
53319
+ if (kids.length === 1 && parentDictionary && parentDictionary.get('Type').name === 'Pages') {
53320
+ this._removeParent(parentReference, parentDictionary);
53321
+ }
53322
+ else {
53323
+ kids = kids.filter(function (item) { return item !== referenceToRemove; });
53324
+ parentDictionary.update('Kids', kids);
53325
+ this._updatePageCount(parentDictionary, -1);
53326
+ }
53311
53327
  }
53312
53328
  }
53313
53329
  };