public class DocumentMergeOperation extends Object implements Operation
To know more about document generation and document templates, please see the documentation
Sample Usage:
JSONObject jsonDataForMerge = new JSONObject("{\"customerName\": \"James\",\"customerVisits\": 100}");
DocumentMergeOptions documentMergeOptions = new DocumentMergeOptions(jsonDataForMerge, OutputFormat.PDF);
DocumentMergeOperation docMergeOperation = DocumentMergeOperation.createNew(documentMergeOptions);
documentMergeOptions.setInput(FileRef.createFromLocalFile("~/Documents/documentTemplate.docx",
DocumentMergeOptions.SupportedSourceFormat.DOCX.getMediaType()));
Credentials credentials = Credentials.serviceAccountCredentialsBuilder().fromFile("pdfservices-api-credentials.json").build();
FileRef result = createPdfOperation.execute(ExecutionContext.create(credentials));
result.saveAs("output/DocumentMergeOutput.pdf");
Modifier and Type | Class and Description |
---|---|
static class |
DocumentMergeOperation.SupportedSourceFormat
Supported source file formats for
DocumentMergeOperation . |
Modifier and Type | Method and Description |
---|---|
static DocumentMergeOperation |
createNew(DocumentMergeOptions documentMergeOptions)
Constructs a
DocumentMergeOperation instance. |
FileRef |
execute(ExecutionContext context)
Executes this operation synchronously using the supplied context and returns a new FileRef instance for the resulting Merged file.
|
void |
setInput(FileRef documentTemplate)
Sets the input MS Word based document template
|
public void setInput(FileRef documentTemplate)
documentTemplate
- an input file; Cannot be nullpublic static DocumentMergeOperation createNew(DocumentMergeOptions documentMergeOptions)
DocumentMergeOperation
instance.documentMergeOptions
- for merging document template with provided input JSON data; Cannot be nullDocumentMergeOperation
instancepublic FileRef execute(ExecutionContext context) throws ServiceApiException, IOException, ServiceUsageException
The resulting file may be stored in the system temporary directory (per java.io.tmpdir System property).
See FileRef
for how temporary resources are cleaned up.
execute
in interface Operation
context
- the context in which to execute the operationServiceApiException
- if an API call results in an error responseIOException
- if there is an error in reading either the input source or the resulting PDF fileServiceUsageException
- if service usage limits have been reached or credentials quota has been exhaustedCopyright © 2022 Adobe. All rights reserved.