all files / document/ pdf-document.js

85.22% Statements 98/115
78.72% Branches 37/47
88.46% Functions 23/26
84.82% Lines 95/112
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197                      452×   452×           987×           28×   28×               522×                                             1827×         1827×                           220×   220×                                                                
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "./../input-output/pdf-writer", "./../input-output/pdf-main-object-collection", "./pdf-document-base", "./../input-output/pdf-cross-table", "./pdf-catalog", "./../pages/pdf-page-settings", "./../pages/pdf-section-collection", "./../pages/pdf-document-page-collection", "./../general/pdf-cache-collection", "./../graphics/enum", "./pdf-document-template", "./../graphics/fonts/enum", "./../graphics/fonts/pdf-standard-font"], function (require, exports, pdf_writer_1, pdf_main_object_collection_1, pdf_document_base_1, pdf_cross_table_1, pdf_catalog_1, pdf_page_settings_1, pdf_section_collection_1, pdf_document_page_collection_1, pdf_cache_collection_1, enum_1, pdf_document_template_1, enum_2, pdf_standard_font_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfDocument = (function (_super) {
        __extends(PdfDocument, _super);
        function PdfDocument(isMerging) {
            var _this = _super.call(this) || this;
            _this.defaultMargin = 40.0;
            _this.streamWriter = null;
            _this.document = _this;
            var isMerge = false;
            Eif (typeof isMerging === 'undefined') {
                PdfDocument.cacheCollection = new pdf_cache_collection_1.PdfCacheCollection();
                isMerge = false;
            }
            else {
                isMerge = isMerging;
            }
            var objects = new pdf_main_object_collection_1.PdfMainObjectCollection();
            _this.setMainObjectCollection(objects);
            var crossTable = new pdf_cross_table_1.PdfCrossTable();
            crossTable.isMerging = isMerge;
            crossTable.document = _this;
            _this.setCrossTable(crossTable);
            var catalog = new pdf_catalog_1.PdfCatalog();
            _this.setCatalog(catalog);
            objects.add(catalog);
            catalog.position = -1;
            _this.sectionCollection = new pdf_section_collection_1.PdfSectionCollection(_this);
            _this.documentPageCollection = new pdf_document_page_collection_1.PdfDocumentPageCollection(_this);
            catalog.pages = _this.sectionCollection;
            return _this;
        }
        Object.defineProperty(PdfDocument, "defaultFont", {
            get: function () {
                if (this.defaultStandardFont == null) {
                    this.defaultStandardFont = new pdf_standard_font_1.PdfStandardFont(enum_2.PdfFontFamily.Helvetica, 8);
                }
                return this.defaultStandardFont;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument.prototype, "sections", {
            get: function () {
                return this.sectionCollection;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument.prototype, "pageSettings", {
            get: function () {
                if (this.settings == null) {
                    this.settings = new pdf_page_settings_1.PdfPageSettings(this.defaultMargin);
                }
                return this.settings;
            },
            set: function (value) {
                this.settings = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument.prototype, "pages", {
            get: function () {
                return this.documentPageCollection;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument, "cache", {
            get: function () {
                Iif (typeof PdfDocument.cacheCollection === 'undefined' || PdfDocument.cacheCollection == null) {
                    return new pdf_cache_collection_1.PdfCacheCollection();
                }
                return PdfDocument.cacheCollection;
            },
            set: function (value) {
                this.cacheCollection = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument, "enableCache", {
            get: function () {
                return this.isCacheEnabled;
            },
            set: function (value) {
                this.isCacheEnabled = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument.prototype, "colorSpace", {
            get: function () {
                Iif ((this.pdfColorSpace === enum_1.PdfColorSpace.Rgb) || ((this.pdfColorSpace === enum_1.PdfColorSpace.Cmyk)
                    || (this.pdfColorSpace === enum_1.PdfColorSpace.GrayScale))) {
                    return this.pdfColorSpace;
                }
                else {
                    return enum_1.PdfColorSpace.Rgb;
                }
            },
            set: function (value) {
                Iif ((value === enum_1.PdfColorSpace.Rgb) || ((value === enum_1.PdfColorSpace.Cmyk) ||
                    (value === enum_1.PdfColorSpace.GrayScale))) {
                    this.pdfColorSpace = value;
                }
                else {
                    this.pdfColorSpace = enum_1.PdfColorSpace.Rgb;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocument.prototype, "template", {
            get: function () {
                if (this.pageTemplate == null) {
                    this.pageTemplate = new pdf_document_template_1.PdfDocumentTemplate();
                }
                return this.pageTemplate;
            },
            set: function (value) {
                this.pageTemplate = value;
            },
            enumerable: true,
            configurable: true
        });
        PdfDocument.prototype.docSave = function (stream, arg2, arg3) {
            this.checkPagesPresence();
            Iif (stream === null) {
                throw new Error('ArgumentNullException : stream');
            }
            this.streamWriter = stream;
            var writer = new pdf_writer_1.PdfWriter(stream);
            writer.document = this;
            Eif (typeof arg2 === 'boolean' && typeof arg3 === 'undefined') {
                return this.crossTable.save(writer);
            }
            else {
                this.crossTable.save(writer, arg2);
            }
        };
        PdfDocument.prototype._docSave = function () {
            var stream = new pdf_writer_1.PdfWriterHelper();
            this.checkPagesPresence();
            if (stream === null) {
                throw new Error('ArgumentNullException : stream');
            }
            this.streamWriter = stream;
            var writer = new pdf_writer_1.PdfWriter(stream);
            writer.document = this;
            return this.crossTable._save(writer);
        };
        PdfDocument.prototype.checkPagesPresence = function () {
            Iif (this.pages.count === 0) {
                this.pages.add();
            }
        };
        PdfDocument.prototype.destroy = function () {
            this.catalog = undefined;
            this.colorSpace = undefined;
            this.currentSavingObj = undefined;
            this.documentPageCollection = undefined;
            this.isStreamCopied = undefined;
            this.pageSettings = undefined;
            this.pageTemplate = undefined;
            this.pdfColorSpace = undefined;
            this.sectionCollection = undefined;
            PdfDocument.cache.destroy();
            this.crossTable.pdfObjects.destroy();
            PdfDocument.cache = undefined;
            Eif (this.streamWriter) {
                this.streamWriter.destroy();
            }
        };
        PdfDocument.defaultStandardFont = null;
        PdfDocument.isCacheEnabled = true;
        return PdfDocument;
    }(pdf_document_base_1.PdfDocumentBase));
    exports.PdfDocument = PdfDocument;
});