define(["require", "exports", "./pdf-page", "./../collections/dictionary"], function (require, exports, pdf_page_1, dictionary_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PdfDocumentPageCollection = (function () {
function PdfDocumentPageCollection(document) {
this.pdfPageCollectionIndex = new dictionary_1.Dictionary();
this.document = document;
}
Object.defineProperty(PdfDocumentPageCollection.prototype, "count", {
get: function () {
return this.countPages();
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfDocumentPageCollection.prototype, "pageCollectionIndex", {
get: function () {
return this.pdfPageCollectionIndex;
},
enumerable: true,
configurable: true
});
PdfDocumentPageCollection.prototype.add = function (page) {
if (typeof page === 'undefined') {
var page_1 = new pdf_page_1.PdfPage();
this.add(page_1);
return page_1;
}
else {
var section = this.getLastSection();
section.add(page);
}
};
PdfDocumentPageCollection.prototype.getLastSection = function () {
var sc = this.document.sections;
if (sc.section.length === 0) {
sc.add();
}
var section = sc.section[sc.section.length - 1];
return section;
};
PdfDocumentPageCollection.prototype.onPageAdded = function (args) {
};
PdfDocumentPageCollection.prototype.countPages = function () {
var sc = this.document.sections;
var count = 0;
for (var index = 0; index < sc.section.length; index++) {
count += sc.section[index].count;
}
return count;
};
PdfDocumentPageCollection.prototype.getPageByIndex = function (index) {
return this.getPage(index);
};
PdfDocumentPageCollection.prototype.getPage = function (index) {
Iif ((index < 0) || (index >= this.count)) {
throw Error('ArgumentOutOfRangeException("index", "Value can not be less 0")');
}
var page = null;
var sectionStartIndex = 0;
var sectionCount = 0;
var pageIndex = 0;
var length = this.document.sections.count;
for (var i = 0; i < length; i++) {
var section = this.document.sections.section[i];
sectionCount = section.count;
pageIndex = index - sectionStartIndex;
Eif ((index >= sectionStartIndex && pageIndex < sectionCount)) {
page = section.getPages()[pageIndex];
break;
}
sectionStartIndex += sectionCount;
}
return page;
};
PdfDocumentPageCollection.prototype.indexOf = function (page) {
var index = -1;
Iif (page == null) {
throw new Error('ArgumentNullException: page');
}
else {
var numPages = 0;
for (var i = 0, len = this.document.sections.count; i < len; i++) {
var section = this.document.sections.pdfSectionCollection(i);
index = section.indexOf(page);
Eif (index >= 0) {
index += numPages;
break;
}
else {
index = -1;
}
numPages += section.count;
}
}
return index;
};
PdfDocumentPageCollection.prototype.remove = function (page) {
if (page == null) {
throw Error('ArgumentNullException("page")');
}
var section = null;
var len;
for (var i = 0, len_1 = this.document.sections.count; i < len_1; i++) {
section = this.document.sections.pdfSectionCollection(i);
if (section.pages.contains(page)) {
section.pages.remove(page);
break;
}
}
return section;
};
return PdfDocumentPageCollection;
}());
exports.PdfDocumentPageCollection = PdfDocumentPageCollection;
});
|