@adobe/pdfservices-node-sdk
Version:
The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.
94 lines • 4.28 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.PDFPropertiesJob = 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 PDFPropertiesInternalAssetRequest_1 = require("../../internal/dto/request/pdfproperties/PDFPropertiesInternalAssetRequest");
const PDFPropertiesExternalAssetRequest_1 = require("../../internal/dto/request/pdfproperties/PDFPropertiesExternalAssetRequest");
const PDFServicesHelper_1 = require("../../internal/PDFServicesHelper");
/**
* A job that is used to fetch properties from an input PDF file. The properties are returned in a POJO.
* <p>
*
* @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 params = new PDFPropertiesParams({
* includePageLevelProperties: true
* });
*
* const job = new PDFPropertiesJob({inputAsset, params});
*
* const pollingURL = await pdfServices.submit({job});
*
* const pdfServicesResponse = await pdfServices.getJobResult({
* pollingURL,
* resultType: PDFPropertiesResult
* });
*
* const pdfProperties = pdfServicesResponse.result.pdfProperties;
* ```
*/
class PDFPropertiesJob extends PDFServicesJob_1.PDFServicesJob {
/**
* Constructs a new `PDFPropertiesJob` instance.
*
* @param params The parameters for constructing an instance of `PDFPropertiesJob`.
* @param params.inputAsset The input asset for the job. Cannot be undefined.
* @param [params.params] {@link PDFPropertiesParams} object to specify the properties to be fetched from the PDF.
*/
constructor(params) {
super();
ValidationUtil_1.ValidationUtil.validatePDFPropertiesJobParams(params);
this._inputAsset = params.inputAsset;
this._pdfPropertiesParams = params.params;
}
/**
* @hidden
*/
async process(executionContext, notifierConfigList) {
this.validate(executionContext);
const pdfPropertiesRequest = this.generatePDFServicesAPIRequest(notifierConfigList), xRequestId = (0, uuid_1.v4)(), response = await PDFServicesHelper_1.PDFServicesHelper.submitJob(executionContext, pdfPropertiesRequest, xRequestId, OperationHeaderInfoEndpointMap_1.OperationHeaderInfoEndpointMap.PDF_PROPERTIES);
return response.headers[DefaultRequestHeaders_1.DefaultRequestHeaders.LOCATION_HEADER_NAME];
}
generatePDFServicesAPIRequest(notifierConfigList) {
let pdfPropertiesRequest;
if (this._inputAsset instanceof CloudAsset_1.CloudAsset) {
pdfPropertiesRequest = new PDFPropertiesInternalAssetRequest_1.PDFPropertiesInternalAssetRequest(this._inputAsset.assetId, this._pdfPropertiesParams, notifierConfigList);
}
else {
pdfPropertiesRequest = new PDFPropertiesExternalAssetRequest_1.PDFPropertiesExternalAssetRequest(this._inputAsset, this._pdfPropertiesParams, notifierConfigList);
}
return pdfPropertiesRequest;
}
}
exports.PDFPropertiesJob = PDFPropertiesJob;
//# sourceMappingURL=PDFPropertiesJob.js.map