com.adobe.platform.operation.internal.service.CompressPDFService Maven / Gradle / Ivy
/*
* 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.
*/
package com.adobe.platform.operation.internal.service;
import com.adobe.platform.operation.internal.FileRefImpl;
import com.adobe.platform.operation.internal.InternalExecutionContext;
import com.adobe.platform.operation.internal.api.CPFApi;
import com.adobe.platform.operation.internal.cpf.constants.CPFConstants;
import com.adobe.platform.operation.internal.cpf.dto.request.ContentAnalyzerRequests;
import com.adobe.platform.operation.internal.cpf.dto.request.Engine;
import com.adobe.platform.operation.internal.http.DefaultRequestHeaders;
import com.adobe.platform.operation.internal.http.HttpResponse;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class CompressPDFService {
private static final String OUTPUT_FORMAT_SPECIFIER = "application/pdf";
public static String compressPDF(InternalExecutionContext context,
FileRefImpl sourceFileRef,
String operation) throws FileNotFoundException {
try {
// Build EnginesDto for ContentAnalyzerRequest
Engine engine = Engine.builder(CPFConstants.CompressPDF.V2_ENGINE_EXECUTION_INFO,
sourceFileRef.getMediaType(),
OUTPUT_FORMAT_SPECIFIER)
.build();
// Create ContentAnalyzerRequest
ContentAnalyzerRequests contentAnalyzerRequests
= new ContentAnalyzerRequests(CPFConstants.CompressPDF.V2_ENGINE_NAME, engine);
// Prepare the sourceFileRefList
List sourceFileRefList = new ArrayList<>();
sourceFileRefList.add(sourceFileRef);
HttpResponse response = CPFApi.cpfPredictApi(context, contentAnalyzerRequests,
sourceFileRefList, String.class, operation);
return response.getHeaders().get(DefaultRequestHeaders.LOCATION_HEADER_NAME);
} catch (FileNotFoundException fe) {
throw fe;
}
}
}