UNPKG

@adobe/pdfservices-node-sdk

Version:

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

93 lines 4.4 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.CompressPDFJob = 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 CompressPDFInternalAssetRequest_1 = require("../../internal/dto/request/compresspdf/CompressPDFInternalAssetRequest"); const CompressPDFExternalAssetRequest_1 = require("../../internal/dto/request/compresspdf/CompressPDFExternalAssetRequest"); const PDFServicesHelper_1 = require("../../internal/PDFServicesHelper"); /** * A job that reduces the size of a PDF file. Allows specifying {@link CompressionLevel} for compressing PDF * * @example * Sample Usage: * ```js * const readStream = fs.createReadStream("<SOURCE_PATH>"); * * const credentials = new ServicePrincipalCredentials({ * clientId: process.env.PDF_SERVICES_CLIENT_ID, * clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET * }); * * const pdfServices = new PDFServices({credentials}); * * const inputAsset = await pdfServices.upload({ * readStream, * mimeType: MimeType.PDF * }); * * const job = new CompressPDFJob({inputAsset}); * * const pollingURL = await pdfServices.submit({job}); * * const pdfServicesResponse = await pdfServices.getJobResult({ * pollingURL, * resultType: CompressPDFResult * }); * * const resultAsset = pdfServicesResponse.result.asset; * const streamAsset = await pdfServices.getContent({asset: resultAsset}); * ``` */ class CompressPDFJob extends PDFServicesJob_1.PDFServicesJob { /** * Constructs a new `CompressPDFJob` instance. * * @param params The parameters for constructing an instance of `CompressPDFJob`. * @param params.inputAsset {@link Asset} object containing the input file. Cannot be undefined. * @param [params.params] {@link CompressPDFParams} object containing the compression level. * @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.validateCompressPDFJobParams(params); this._inputAsset = params.inputAsset; this._compressPDFParams = params.params; this._outputAsset = params.outputAsset; } /** * @hidden */ async process(executionContext, notifyConfigList) { this.validate(executionContext); const compressPDFRequest = this.generatePDFServicesAPIRequest(notifyConfigList), xRequestId = (0, uuid_1.v4)(), response = await PDFServicesHelper_1.PDFServicesHelper.submitJob(executionContext, compressPDFRequest, xRequestId, OperationHeaderInfoEndpointMap_1.OperationHeaderInfoEndpointMap.COMPRESS_PDF); return response.headers[DefaultRequestHeaders_1.DefaultRequestHeaders.LOCATION_HEADER_NAME]; } generatePDFServicesAPIRequest(notifyConfigList) { let compressPDFRequest; if (this._inputAsset instanceof CloudAsset_1.CloudAsset) { compressPDFRequest = new CompressPDFInternalAssetRequest_1.CompressPDFInternalAssetRequest(this._inputAsset.assetId, this._compressPDFParams, notifyConfigList); } else { compressPDFRequest = new CompressPDFExternalAssetRequest_1.CompressPDFExternalAssetRequest(this._inputAsset, this._compressPDFParams, this._outputAsset, notifyConfigList); } return compressPDFRequest; } } exports.CompressPDFJob = CompressPDFJob; //# sourceMappingURL=CompressPDFJob.js.map