DocumentMergeOperation

DocumentMergeOperation

An operation that enables the clients to produce high fidelity PDF and Word documents with dynamic data inputs. This operation merges the JSON data with the Word template to create dynamic documents for contracts and agreements, invoices, proposals, reports, forms, branded marketing documents and more.

To know more about document generation and document templates, please see the documentation

Sample Usage:


 const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
           .withClientId("PDF_SERVICES_CLIENT_ID")
           .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
           .build(),
       executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
       DocumentMerge = PDFServicesSdk.DocumentMerge,
       documentMergeOptions = DocumentMerge.options,
       jsonDataForMerge = JSON.parse("{\"customerName\": \"James\", \"customerVisits\": 100}");
       options = new documentMergeOptions.DocumentMergeOptions(jsonDataForMerge, documentMergeOptions.OutputFormat.PDF),
       documentMergeOperation = DocumentMerge.Operation.createNew(options),
       input = PDFServicesSdk.FileRef.createFromLocalFile('~/Documents/DocumentMergeOperationInput.docx', DocumentMerge.SupportedSourceFormat.docx);

 documentMergeOperation.setInput(input);

 documentMergeOperation.execute(executionContext)
     .then(result => result.saveAsFile('DocumentMergeOperationOutput.pdf'))
     .catch(err => console.log(err));

Members

(static, constant) SupportedSourceFormat

Description:
Properties:
Name Type Description
docx string

Represents "application/vnd.openxmlformats-officedocument.wordprocessingml.document" media type

Supported source file formats for DocumentMergeOperation.

Methods

(static) createNew(optionsnon-null) → {DocumentMergeOperation}

Description:
Parameters:
Name Type Description
options DocumentMergeOptions

Options for merging a document template with provided input JSON data; Cannot be null.

Returns:

A new DocumentMergeOperation instance.

Type
DocumentMergeOperation

setInput(documentTemplatenon-null)

Description:
  • Sets the input DOCX based document template.

Parameters:
Name Type Description
documentTemplate FileRef

An input file; Cannot be null.

execute(contextnon-null) → {Promise.<FileRef>}

Description:
  • Executes this operation using the supplied context and returns a Promise which resolves to the operation result.

    The resulting file may be stored in the system temporary directory (per the os.tempdir(), symlinks are resolved to the actual path). See FileRef for how temporary resources are cleaned up.

Parameters:
Name Type Description
context ExecutionContext

The context in which the operation will be executed.

Throws:
  • if an API call results in an error response.

    Type
    ServiceApiError
  • if service usage limits have been reached or credentials quota has been exhausted.

    Type
    ServiceUsageError
Returns:

A promise which resolves to the operation result.

Type
Promise.<FileRef>