@adobe/pdfservices-node-sdk
Version:
The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.
83 lines • 3.62 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.ReplacePagesParams = 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 replacing pages of a PDF using {@link ReplacePagesJob}.
*/
class ReplacePagesParams {
/**
* Constructs a new `ReplacePagesParams` instance.
*
* @param baseAsset - The base asset to be used for replacing pages. Cannot be undefined.
*/
constructor(baseAsset) {
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(baseAsset, "Base Asset");
this._baseAsset = baseAsset;
this._assetsToReplace = new Map();
}
/**
* @internal Used internally by this SDK, not intended to be called by clients.
*/
get assetsToReplace() {
return this._assetsToReplace;
}
/**
* Returns the base PDF {@link Asset} to which pages will be replaced.
*
* @returns an {@link Asset} instance
*/
get baseAsset() {
return this._baseAsset;
}
/**
* Adds the specified pages of the input PDF file to be replaced 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 be replaced.
* @param params.asset - 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 `ReplacePagesParams` instance.
*/
addPagesForReplace(params) {
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(params, "Params");
ObjectUtil_1.ObjectUtil.requireNonNullOrUndefined(params.asset, "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.asset, params.pageRanges);
this._assetsToReplace.set(params.basePage, combinePDFJobInput);
return this;
}
/**
* @hidden
*/
validate() {
ValidationUtil_1.ValidationUtil.validateReplaceFilesInputs(this._baseAsset, this._assetsToReplace);
}
}
exports.ReplacePagesParams = ReplacePagesParams;
//# sourceMappingURL=ReplacePagesParams.js.map