Class DocumentMergeJob


  • public class DocumentMergeJob
    extends PDFServicesJob
    A job 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:

    
                 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);
    
                 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());
    
                 JSONObject jsonDataForMerge = new JSONObject("{\"customerName\": \"James\",\"customerVisits\": 100}");
                 DocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder()
                         .withJsonDataForMerge(jsonDataForMerge)
                         .withOutputFormat(OutputFormat.PDF)
                         .build();
    
                 DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);
    
                 String location = pdfServices.submit(documentMergeJob);
                 PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);
    
                 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
                 StreamAsset result = pdfServices.getContent(resultAsset);
     
    • Constructor Detail

      • DocumentMergeJob

        public DocumentMergeJob​(Asset asset,
                                DocumentMergeParams documentMergeParams)
        Constructs a new DocumentMergeJob instance.
        Parameters:
        asset - Asset object containing the input file; can not be null.
        documentMergeParams - DocumentMergeParams object containing the parameters for document generation; can not be null.
    • Method Detail

      • setOutput

        public DocumentMergeJob setOutput​(Asset asset)
        Sets the output asset for the job. @note External assets can be set as output only when input is external asset as well
        Parameters:
        asset - Asset object representing the output asset; can not be null.
        Returns:
        DocumentMergeJob instance