com.adobe.pdfservices.operation.pdfjobs.jobs.PDFElectronicSealJob Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdfservices-sdk Show documentation
Show all versions of pdfservices-sdk Show documentation
Adobe PDF Services SDK allows you to access RESTful APIs to create, convert, and manipulate PDFs within your applications.
Older versions can be found under groupId: com.adobe.documentservices, artifactId: pdftools-sdk
/*
* 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.
*/
package com.adobe.pdfservices.operation.pdfjobs.jobs;
import com.adobe.pdfservices.operation.PDFServicesJob;
import com.adobe.pdfservices.operation.config.notifier.NotifierConfig;
import com.adobe.pdfservices.operation.exception.ServiceApiException;
import com.adobe.pdfservices.operation.internal.ExecutionContext;
import com.adobe.pdfservices.operation.internal.PDFServicesHelper;
import com.adobe.pdfservices.operation.internal.constants.CustomErrorMessages;
import com.adobe.pdfservices.operation.internal.constants.OperationHeaderInfoEndpointMap;
import com.adobe.pdfservices.operation.internal.dto.request.PlatformApiRequest;
import com.adobe.pdfservices.operation.internal.dto.request.electronicseal.PDFElectronicSealExternalAssetRequest;
import com.adobe.pdfservices.operation.internal.dto.request.electronicseal.PDFElectronicSealInternalAssetRequest;
import com.adobe.pdfservices.operation.internal.http.DefaultRequestHeaders;
import com.adobe.pdfservices.operation.internal.http.HttpResponse;
import com.adobe.pdfservices.operation.internal.util.ObjectUtil;
import com.adobe.pdfservices.operation.io.Asset;
import com.adobe.pdfservices.operation.io.CloudAsset;
import com.adobe.pdfservices.operation.io.ExternalAsset;
import com.adobe.pdfservices.operation.pdfjobs.params.electronicseal.PDFElectronicSealParams;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
* A job that allows clients to apply an electronic seal onto various PDF documents such as
* agreements, invoices, and more.
*
* To know more about PDF Electronic Seal, please see the
* documentation.
*
* Sample Usage:
*
* {@code
* InputStream inputStream = new FileInputStream(new File("SOURCE_PATH"));
*
* Credentials credentials = new ServicePrincipalCredentials(
* System.getenv("PDF_SERVICES_CLIENT_ID"),
* System.getenv("PDF_SERVICES_CLIENT_SECRET"));
*
* PDFServices pdfServices = new PDFServices(credentials);
*
* CertificateCredentials certificateCredentials = CertificateCredentials.cscCredentialBuilder()
* .withProviderName("")
* .withCredentialID("")
* .withPin("")
* .withCSCAuthContext(new CSCAuthContext(""))
* .build();
*
* String sealFieldName = "Signature1";
* FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName)
* .setFieldLocation(new FieldLocation(150, 250, 350, 200))
* .setPageNumber(1)
* .build();
*
* PDFElectronicSealParams pdfElectronicSealParams = PDFElectronicSealParams.pdfElectronicSealParamsBuilder(certificateCredentials, fieldOptions).build();
*
* PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams);
*
* String location = pdfServices.submit(pdfElectronicSealJob);
* PDFServicesResponse pdfServicesResponse = pdfServices.getJobResult(location, PDFElectronicSealResult.class);
*
* Asset resultAsset = pdfServicesResponse.getResult().getAsset();
* StreamAsset streamAsset = pdfServices.getContent(esealResult);
* }
*
*/
public class PDFElectronicSealJob extends PDFServicesJob {
Asset inputDocumentAsset;
Asset sealImageAsset;
private Asset outputAsset;
PDFElectronicSealParams pdfElectronicSealParams;
/**
* Constructs a new {@code PDFElectronicSealJob} instance.
*
* @param inputDocumentAsset {@link Asset} object containing the input file; can not be null.
* @param pdfElectronicSealParams {@link PDFElectronicSealParams} object containing the parameters for electronic
* seal; can not be null.
*/
public PDFElectronicSealJob(Asset inputDocumentAsset, PDFElectronicSealParams pdfElectronicSealParams) {
ObjectUtil.requireNonNull(inputDocumentAsset, String.format(CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL,
"Input Document Asset"));
ObjectUtil.requireNonNull(pdfElectronicSealParams, String.format(CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL,
"PDF Electronic Seal parameters"));
this.inputDocumentAsset = inputDocumentAsset;
this.pdfElectronicSealParams = pdfElectronicSealParams;
}
@Override
protected String process(ExecutionContext executionContext) throws ServiceApiException {
return this.process(executionContext, null);
}
@Override
protected String process(ExecutionContext executionContext, List notifyConfigList) throws ServiceApiException {
this.validate(executionContext);
PlatformApiRequest pdfElectronicSealRequest = generatePlatformApiRequest(notifyConfigList);
String xRequestId = UUID.randomUUID().toString();
HttpResponse response = PDFServicesHelper.submitJob(executionContext, pdfElectronicSealRequest,
xRequestId, OperationHeaderInfoEndpointMap.E_SEAL);
return response.getHeaders().get(DefaultRequestHeaders.LOCATION_HEADER_NAME);
}
/**
* Sets the seal image asset for the job.
*
* @param sealImageAsset {@link Asset} object representing the seal image asset; can not be null.
*/
public void setSealImageAsset(Asset sealImageAsset) {
ObjectUtil.requireNonNull(sealImageAsset, String.format(CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL,
"Seal " + "Image Asset"));
if (!this.inputDocumentAsset.getClass().equals(sealImageAsset.getClass())) {
throw new IllegalArgumentException("Seal Image Asset should be of same type as input document asset");
}
this.sealImageAsset = sealImageAsset;
}
/**
* Sets the output asset for the job.
* {@code @note} External assets can be set as output only when input is external asset as well
*
* @param asset {@link Asset} object representing the output asset; can not be null.
* @return {@code PDFElectronicSealJob} instance
*/
public PDFElectronicSealJob setOutput(Asset asset) {
ObjectUtil.requireNonNull(asset, String.format(CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL, "Output asset"));
if (this.inputDocumentAsset instanceof CloudAsset) {
throw new IllegalArgumentException(CustomErrorMessages.SET_OUTPUT_VALIDATE);
}
this.outputAsset = asset;
return this;
}
private PlatformApiRequest generatePlatformApiRequest(List notifyConfigList) {
PlatformApiRequest pdfElectronicSealRequest;
if (this.inputDocumentAsset instanceof CloudAsset) {
String sealImageAssetID = Objects.nonNull(this.sealImageAsset) ?
( (CloudAsset) this.sealImageAsset ).getAssetId() : null;
pdfElectronicSealRequest =
new PDFElectronicSealInternalAssetRequest(( (CloudAsset) this.inputDocumentAsset ).getAssetId(),
sealImageAssetID, this.pdfElectronicSealParams,
notifyConfigList);
} else {
pdfElectronicSealRequest =
new PDFElectronicSealExternalAssetRequest((ExternalAsset) this.inputDocumentAsset,
(ExternalAsset) this.sealImageAsset,
this.pdfElectronicSealParams, notifyConfigList)
.setOutput((ExternalAsset) outputAsset);
}
return pdfElectronicSealRequest;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy