@adobe/pdfservices-node-sdk
Version:
The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.
95 lines • 3.98 kB
JavaScript
;
/*
* 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.InsertPagesParams = void 0;
const CombinePDFJobInput_1 = require("../../../internal/params/CombinePDFJobInput");
const ObjectUtil_1 = require("../../../internal/util/ObjectUtil");
const PageRanges_1 = require("../PageRanges");
const CustomErrorMessages_1 = require("../../../internal/constants/CustomErrorMessages");
const ValidationUtil_1 = require("../../../internal/util/ValidationUtil");
/**
* Parameters for inserting pages into a PDF using {@link InsertPagesJob}.
*/
class InsertPagesParams {
/**
* Constructs a new `InsertPagesParams` instance.
*
* @param baseAsset the base asset to insert pages into.
*/
constructor(baseAsset) {
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(baseAsset, "Base Asset");
this._baseAsset = baseAsset;
this._assetsToInsert = new Map();
}
/**
* @internal Used internally by this SDK, not intended to be called by clients.
*/
get assetsToInsert() {
return this._assetsToInsert;
}
/**
* Returns the base asset to insert pages into.
*
* @returns the base asset to insert pages into.
*/
get baseAsset() {
return this._baseAsset;
}
/**
* Adds the specified pages of the input PDF file to be inserted at the specified page of the base PDF file.
*
* This method can be invoked multiple times with the same or different input PDF files.
*
* @param params - The parameters for adding pages to insert at.
* @param params.inputAsset - The PDF file for insertion. Cannot be undefined.
* @param [params.pageRanges] - The page ranges of the input PDF file. If not specified, all pages are included.
* @param params.basePage - The page of the base PDF file. Cannot be undefined.
* @returns this `InsertPagesParams` instance.
*/
addPagesToInsertAt(params) {
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(params, "Params");
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(params.inputAsset, "Input Asset");
ObjectUtil_1.ObjectUtil.requireValidPositiveInteger(params.basePage, "Base Page");
if (ObjectUtil_1.ObjectUtil.isUndefined(params.pageRanges)) {
const pageRanges = new PageRanges_1.PageRanges();
pageRanges.addAll();
// eslint-disable-next-line no-param-reassign
params.pageRanges = pageRanges;
}
if (ObjectUtil_1.ObjectUtil.isNull(params.pageRanges) || params.pageRanges?.isEmpty()) {
throw new TypeError(`Page Ranges ${CustomErrorMessages_1.CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL_OR_EMPTY}`);
}
const combinePDFJobInput = new CombinePDFJobInput_1.CombinePDFJobInput(params.inputAsset, params.pageRanges);
this.updateFilesToInsert(params.basePage, combinePDFJobInput);
return this;
}
updateFilesToInsert(index, combinePDFJobInput) {
if (this._assetsToInsert.has(index)) {
const inputList = this._assetsToInsert.get(index);
if (inputList) {
inputList.push(combinePDFJobInput);
}
}
else {
const inputList = [combinePDFJobInput];
this._assetsToInsert.set(index, inputList);
}
}
/**
* @hidden
*/
validate() {
ValidationUtil_1.ValidationUtil.validateInsertAssetInputs(this._baseAsset, this._assetsToInsert);
}
}
exports.InsertPagesParams = InsertPagesParams;
//# sourceMappingURL=InsertPagesParams.js.map