UNPKG

@adobe/pdfservices-node-sdk

Version:

The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.

95 lines 3.07 kB
"use strict"; /* * Copyright 2024 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PageRanges = void 0; const PageRange_1 = require("../../internal/params/PageRange"); const ObjectUtil_1 = require("../../internal/util/ObjectUtil"); /** * Page ranges of a file, inclusive of start and end page index, where page index starts from 1. */ class PageRanges { /** * Constructs a new PageRanges instance with no pages added. */ constructor() { this._ranges = []; } /** * Adds a single page. Page index starts from 1. * * @param page - The single page index */ addSinglePage(page) { ObjectUtil_1.ObjectUtil.requireValidNonNegativeInteger(page, "Page index"); this._ranges.push(new PageRange_1.PageRange(page, page)); return this; } /** * Adds a page range. Page indexes start from 1. * * @param start - The start page index, inclusive * @param end - The end page index, inclusive */ addRange(start, end) { ObjectUtil_1.ObjectUtil.requireValidNonNegativeInteger(start, "Start page index"); ObjectUtil_1.ObjectUtil.requireValidNonNegativeInteger(end, "End page index"); this._ranges.push(new PageRange_1.PageRange(start, end)); return this; } /** * Adds a page range from {@link start} page index to the last page. Page index starts from 1. * * @param start - The start page index */ addAllFrom(start) { ObjectUtil_1.ObjectUtil.requireValidNonNegativeInteger(start, "Start page index"); this._ranges.push(new PageRange_1.PageRange(start)); return this; } /** * Adds a page range representing all pages. */ addAll() { this._ranges.push(new PageRange_1.PageRange(1)); return this; } /** * @returns string representation of page ranges. */ toString() { return this._ranges.map((range) => range.toString()).join(","); } /** * @hidden */ validate() { if (this._ranges.length > PageRanges.RANGES_MAX_LIMIT) { throw new RangeError("Maximum allowed limit exceeded for page ranges."); } this._ranges.forEach((range) => range.validate()); } /** * @internal Used internally by this SDK, not intended to be called by clients. */ isEmpty() { return this._ranges.length === 0; } /** * @internal Used internally by this SDK, not intended to be called by clients. */ get ranges() { return this._ranges; } } exports.PageRanges = PageRanges; PageRanges.RANGES_MAX_LIMIT = 100; //# sourceMappingURL=PageRanges.js.map