@adobe/pdfservices-node-sdk
Version:
The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.
97 lines (90 loc) • 4.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.AutotagPDFJob = 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 AutotagPDFInternalAssetRequest_1 = require("../../internal/dto/request/autotagpdf/AutotagPDFInternalAssetRequest");
const PDFServicesHelper_1 = require("../../internal/PDFServicesHelper");
const AutotagPDFExternalAssetRequest_1 = require("../../internal/dto/request/autotagpdf/AutotagPDFExternalAssetRequest");
/**
* A job that creates PDF documents with enhanced readability from existing PDF documents.
* An optional tagging report can also be generated which contains the information
* about the tags that the tagged output PDF document contains.
*
* Accessibility tags, used by assistive technology such as screen reader are required to make PDF files compliant.
* However, the generated PDF is not guaranteed to comply with accessibility standards such as WCAG and PDF/UA as
* there could be a need to perform further downstream remediation to meet those standards.
*
* @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 AutotagPDFJob({inputAsset});
const pollingURL = await pdfServices.submit({job});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: AutotagPDFResult
});
const resultAsset = pdfServicesResponse.result.taggedPDF;
const streamAsset = await pdfServices.getContent({asset: resultAsset});
* ```
*/
class AutotagPDFJob extends PDFServicesJob_1.PDFServicesJob {
/**
* Constructs a new `AutotagPDFJob` instance.
* @param params - The parameters for constructing an instance of `AutotagPDFJob`.
* @param params.inputAsset - The input asset for the job. Cannot be undefined.
* @param [params.params] - The {@link AutotagPDFParams} for the job.
* @param [params.outputAsset] - {@link Asset} object representing the output asset.
*/
constructor(params) {
super();
ValidationUtil_1.ValidationUtil.validateAutotagPDFJobParams(params);
this._inputAsset = params.inputAsset;
this._autotagPDFParams = params.params;
this._outputAsset = params.outputAsset;
}
/**
* @hidden
*/
async process(executionContext, notifyConfigList) {
this.validate(executionContext);
const autotagPDFRequest = this.generatePDFServicesAPIRequest(notifyConfigList), xRequestId = (0, uuid_1.v4)(), response = await PDFServicesHelper_1.PDFServicesHelper.submitJob(executionContext, autotagPDFRequest, xRequestId, OperationHeaderInfoEndpointMap_1.OperationHeaderInfoEndpointMap.AUTO_TAG);
return response.headers[DefaultRequestHeaders_1.DefaultRequestHeaders.LOCATION_HEADER_NAME];
}
generatePDFServicesAPIRequest(notifyConfigList) {
let autotagPDFRequest;
if (this._inputAsset instanceof CloudAsset_1.CloudAsset) {
autotagPDFRequest = new AutotagPDFInternalAssetRequest_1.AutotagPDFInternalAssetRequest(this._inputAsset.assetId, this._autotagPDFParams, notifyConfigList);
}
else {
autotagPDFRequest = new AutotagPDFExternalAssetRequest_1.AutotagPDFExternalAssetRequest(this._inputAsset, this._autotagPDFParams, this._outputAsset, notifyConfigList);
}
return autotagPDFRequest;
}
}
exports.AutotagPDFJob = AutotagPDFJob;
//# sourceMappingURL=AutotagPDFJob.js.map