@adobe/pdfservices-node-sdk
Version:
The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.
123 lines • 5.46 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.ProtectPDFJob = void 0;
const uuid_1 = require("uuid");
const PDFServicesJob_1 = require("./PDFServicesJob");
const ValidationUtil_1 = require("../../internal/util/ValidationUtil");
const OperationHeaderInfoEndpointMap_1 = require("../../internal/constants/OperationHeaderInfoEndpointMap");
const DefaultRequestHeaders_1 = require("../../internal/http/DefaultRequestHeaders");
const CloudAsset_1 = require("../../io/CloudAsset");
const ProtectPDFInternalAssetRequest_1 = require("../../internal/dto/request/protectpdf/ProtectPDFInternalAssetRequest");
const ProtectPDFExternalAssetRequest_1 = require("../../internal/dto/request/protectpdf/ProtectPDFExternalAssetRequest");
const PDFServicesHelper_1 = require("../../internal/PDFServicesHelper");
/**
* A job that is used for securing PDF document with password(s).
* The password(s) is used for encrypting the PDF document and setting the restriction on certain features
* like printing, editing and copying in the PDF document.
* <p>
* The supported algorithm for encrypting the PDF document are listed here. The {@link EncryptionAlgorithm} enum can
* be used to set the
* encryption algorithm.
* <ul>
* <li>AES-128</li>
* <li>AES-256</li>
* </ul>
* <p>
* For AES-128 encryption the password supports LATIN-I characters only.
* For AES-256 encryption the password supports Unicode character set.
*
* <p>
*
* @example
* Sample Usage:
* ```js
* const readStream = fs.createReadStream("<SOURCE_PATH>");
*
* const pdfServices = new PDFServices({
* credentials: new ServicePrincipalCredentials({
* clientId: process.env.PDF_SERVICES_CLIENT_ID,
* clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
* })
* });
*
* const inputAsset = await pdfServices.upload({
* readStream,
* mimeType: MimeType.PDF
* });
*
* const permissions = new Permissions({
* permissions: [
* Permission.PRINT_LOW_QUALITY,
* Permission.EDIT_DOCUMENT_ASSEMBLY,
* Permission.COPY_CONTENT
* ]
* });
*
* const params = new ProtectPDFParams({
* userPassword: "openpassword",
* ownerPassword: "permissionspassword",
* permissions: permissions,
* encryptionAlgorithm: EncryptionAlgorithm.AES_256,
* contentEncryption: ContentEncryption.ALL_CONTENT_EXCEPT_METADATA,
* });
*
* const job = new ProtectPDFJob({inputAsset, params});
*
* const pollingURL = await pdfServices.submit({job});
*
* const pdfServicesResponse = await pdfServices.getJobResult({
* pollingURL,
* resultType: ProtectPDFResult
* });
*
* const resultAsset = pdfServicesResponse.result.asset;
* const streamAsset = await pdfServices.getContent({asset: resultAsset});
* ```
*/
class ProtectPDFJob extends PDFServicesJob_1.PDFServicesJob {
/**
* Constructs a new `ProtectPDFJob` instance.
* @param params The parameters for constructing an instance of `ProtectPDFJob`.
* @param params.inputAsset The input asset for the job. Cannot be undefined.
* @param params.params {@link ProtectPDFParams} object to specify the protection parameters.
* @param [params.outputAsset] {@link Asset} object representing the output asset.
* @remarks External assets can be set as output only when input is external asset as well.
*/
constructor(params) {
super();
ValidationUtil_1.ValidationUtil.validateProtectPDFJobParams(params);
this._inputAsset = params.inputAsset;
this._params = params.params;
this._outputAsset = params.outputAsset;
}
/**
* @hidden
*/
async process(executionContext, notifierConfigList) {
this.validate(executionContext);
const protectPDFRequest = this.generatePDFServicesAPIRequest(notifierConfigList), xRequestId = (0, uuid_1.v4)(), response = await PDFServicesHelper_1.PDFServicesHelper.submitJob(executionContext, protectPDFRequest, xRequestId, OperationHeaderInfoEndpointMap_1.OperationHeaderInfoEndpointMap.PROTECT_PDF);
return response.headers[DefaultRequestHeaders_1.DefaultRequestHeaders.LOCATION_HEADER_NAME];
}
generatePDFServicesAPIRequest(notifierConfigList) {
let protectPDFRequest;
if (this._inputAsset instanceof CloudAsset_1.CloudAsset) {
protectPDFRequest = new ProtectPDFInternalAssetRequest_1.ProtectPDFInternalAssetRequest(this._inputAsset.assetId, this._params, notifierConfigList);
}
else {
protectPDFRequest = new ProtectPDFExternalAssetRequest_1.ProtectPDFExternalAssetRequest(this._inputAsset, this._params, this._outputAsset, notifierConfigList);
}
return protectPDFRequest;
}
}
exports.ProtectPDFJob = ProtectPDFJob;
//# sourceMappingURL=ProtectPDFJob.js.map