@adobe/pdftools-extract-node-sdk
Version:
The Document Services PDF Tools Extract Node.js SDK provides APIs for extracting elements and renditions from PDF
54 lines (45 loc) • 2.08 kB
JavaScript
/*
* Copyright 2019 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.
*/
const logger = require('./../logger'),
CPFApi = require('./cpf-api'),
CpfEngine = require('../cpf/request/platform/cpf-engine.js'),
CpfContentAnalyzerRequests = require('../cpf/request/platform/cpf-content-analyzer-requests.js');
/**
* Operation Service is an abstract class. All the document operation services need to inherit this class and have to
* override getCPFMessage. CPFApi class is used for making the CPF Predict and Status API calls.
*/
class CpfOperationService {
constructor() {
if (this.constructor === CpfOperationService) {
throw new TypeError("Can not construct CpfOperationService class.");
}
}
getCPFMessage(operationMessage) {
throw new Error("Method 'getCPFMessage()' must be implemented.");
}
perform(context, operationMessage) {
let cpfMessage = this.getCPFMessage(operationMessage),
engine = new CpfEngine(cpfMessage.cpfEngineConfig),
contentAnalyzerRequests = new CpfContentAnalyzerRequests(engine,cpfMessage.inputDocuments,cpfMessage.params,cpfMessage.outputInfo, cpfMessage.outputRenditions),
contentAnalyzerRequestsJsonString = JSON.stringify(contentAnalyzerRequests);
let operation = operationMessage.operationName.replace(/\s/g, '');
return CPFApi.cpfCreateApi(context, cpfMessage.files, contentAnalyzerRequestsJsonString, operation)
.then(location => {
return CPFApi.cpfStatusApi(context, location, operationMessage.targetFileName);})
.then(targetFileRef => {
targetFileRef.input.isOperationResult = true;
logger.info(operationMessage.operationName + ' successfully completed');
return Promise.resolve(targetFileRef);
})
.catch(res => Promise.reject(res));
}
}
module.exports = CpfOperationService;