Getting Started
This document will guide you through the necessary steps to setup and make a request to the Document Generation API.
Use Document Generation API to merge JSON data into Word based document
templates and produce high fidelity PDF and Word documents from any
application.
To learn more about the Document Generation, read Overview
Live Demo
The Document Generation API Demo demonstrates how easy it is to generate customized documents from Word-based document templates and input JSON data.
How It Works
This section details out step by step instructions to get started with Document Generation.
1. Author your Word-based document templates
Authoring a document template involves adding the template tags to your Word document as illustrated below:
Using MS Word Add-In
The quickest way to author a Word-based document template is by using Adobe Document Generation Word Add-In. The Add-in significantly reduces the time and effort required to insert the template tags into a Word document.
Learn more about our Word Add-in.
Manually
Alternatively, you can create a document template by manually inserting the template tags into a Word document.
Here are some prebuilt sample document templates to start with.
Learn more about Template Tags.
2. Prepare your JSON data
Compose the JSON data that will be merged with your Word-based document template.
Copied to your clipboard{"Client" : {"Name" : "Some Corp Inc","Address" : "Somewhere Street"}}
3. Generate PDF and Word documents using Document Generation API
Once you are ready with the Word-based document template and the JSON data, the final step is to invoke the Document Generation API to generate the output PDF or Word documents.
There are two ways to access the Document Generation API:
3.1. REST API
You can use our cloud based REST API to generate documents.
Before you begin with the REST API, refer How To Get Started to learn more about generating the required credentials and invoking the APIs.
3.2. REST API with External Storage
The Adobe Document Generation API now supports accessing client files directly from their external storage. Clients can use Signed URLs from their storage solution to conveniently access and utilize their files through the Document Generation API.
To learn more, please visit External Storage for Adobe PDF Services APIs.
3.3. PDF Services SDK
Alternatively, you can use our offering through PDF Services SDK.
To get started with PDF Services SDK, refer Quickstarts.
Please allow-list the following hostnames before using Adobe PDF Services SDK:
- ims-na1.adobelogin.com (Required for all the clients)
For clients using SDK version 4.x and above :
- Using United States (Default) region for processing documents :
- dcplatformstorageservice-prod-us-east-1.s3-accelerate.amazonaws.com (Not required, if using external storage for both input and output)
- pdf-services-ue1.adobe.io
- pdf-services.adobe.io (Default URI)
- Using Europe region for processing documents :
- dcplatformstorageservice-prod-eu-west-1.s3.amazonaws.com (Not required, if using external storage for both input and output)
- pdf-services-ew1.adobe.io
For clients using SDK version 3.x and above :
- Using United States region for processing documents :
- dcplatformstorageservice-prod-us-east-1.s3-accelerate.amazonaws.com
- pdf-services-ue1.adobe.io
- pdf-services.adobe.io (Default URI)
- Using Europe region for processing documents :
- dcplatformstorageservice-prod-eu-west-1.s3.amazonaws.com
- pdf-services-ew1.adobe.io
For clients using SDK version upto 2.x :
- cpf-ue1.adobe.io
Generate PDF or Word document
The sample below generates the output document in the PDF format. Similarly, you can specify DOCX as the OutputFormat to generate Word documents.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples// Run the sample:// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.documentmerge.MergeDocumentToPDFpackage com.adobe.pdfservices.operation.samples.documentmerge;public class MergeDocumentToPDF {// Initialize the logger.private static final Logger LOGGER = LoggerFactory.getLogger(MergeDocumentToPDF.class);public static void main(String[] args) {try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/documentMergeTemplate.docx").toPath())) {// Initial setup, create credentials instanceCredentials credentials = new ServicePrincipalCredentials(System.getenv("PDF_SERVICES_CLIENT_ID"),System.getenv("PDF_SERVICES_CLIENT_SECRET"));// Creates a PDF Services instancePDFServices pdfServices = new PDFServices(credentials);// Setup input data for the document merge process.JSONObject jsonDataForMerge = new JSONObject("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}");// Creates an asset(s) from source file(s) and uploadAsset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());// Create parameters for the jobDocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder().withJsonDataForMerge(jsonDataForMerge).withOutputFormat(OutputFormat.PDF).build();// Creates a new job instanceDocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);// Submit the job and gets the job resultString location = pdfServices.submit(documentMergeJob);PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);// Get content from the resulting asset(s)Asset resultAsset = pdfServicesResponse.getResult().getAsset();StreamAsset streamAsset = pdfServices.getContent(resultAsset);// Creates an output stream and copy stream asset's content to itOutputStream outputStream = Files.newOutputStream(new File("output/documentMergeOutput.pdf").toPath());IOUtils.copy(streamAsset.getInputStream(), outputStream);outputStream.close();} catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {LOGGER.error("Exception encountered while executing operation", ex);}}}
Copied to your clipboard// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples// Run the sample:// cd MergeDocumentToPDF/// dotnet run MergeDocumentToPDF.csprojnamespace MergeDocumentToPDF{class Program{private static readonly ILog log = LogManager.GetLogger(typeof(Program));static void Main(){//Configure the loggingConfigureLogging();try{// Initial setup, create credentials instanceICredentials credentials = new ServicePrincipalCredentials(Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));// Creates a PDF Services instancePDFServices pdfServices = new PDFServices(credentials);// Creates an asset from source file and uploadusing Stream inputStream = File.OpenRead(@"documentMergeTemplate.docx");IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.DOCX.GetMIMETypeValue());// Setup input data for the document merge processJObject jsonDataForMerge = JObject.Parse("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}");// Create parameters for the jobDocumentMergeParams documentMergeParams = DocumentMergeParams.DocumentMergeParamsBuilder().WithJsonDataForMerge(jsonDataForMerge).WithOutputFormat(OutputFormat.PDF).Build();// Creates a new job instanceDocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);// Submits the job and gets the job resultString location = pdfServices.Submit(documentMergeJob);PDFServicesResponse<DocumentMergeResult> pdfServicesResponse =pdfServices.GetJobResult<DocumentMergeResult>(location, typeof(DocumentMergeResult));// Get content from the resulting asset(s)IAsset resultAsset = pdfServicesResponse.Result.Asset;StreamAsset streamAsset = pdfServices.GetContent(resultAsset);// Creating output streams and copying stream asset's content to itString outputFilePath = "/output/documentMergeOutput.pdf";new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create();Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath);streamAsset.Stream.CopyTo(outputStream);outputStream.Close();}catch (ServiceUsageException ex){log.Error("Exception encountered while executing operation", ex);}catch (ServiceApiException ex){log.Error("Exception encountered while executing operation", ex);}catch (SDKException ex){log.Error("Exception encountered while executing operation", ex);}catch (IOException ex){log.Error("Exception encountered while executing operation", ex);}catch (Exception ex){log.Error("Exception encountered while executing operation", ex);}}static void ConfigureLogging(){ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));}}}
Copied to your clipboard// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample// Run the sample:// node src/documentmerge/merge-document-to-pdf.jsconst {ServicePrincipalCredentials,PDFServices,MimeType,DocumentMergeParams,OutputFormat,DocumentMergeJob,DocumentMergeResult,SDKError,ServiceUsageError,ServiceApiError} = require("@adobe/pdfservices-node-sdk");const fs = require("fs");(async () => {let readStream;try {// Initial setup, create credentials instanceconst credentials = new ServicePrincipalCredentials({clientId: process.env.PDF_SERVICES_CLIENT_ID,clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET});// Creates a PDF Services instanceconst pdfServices = new PDFServices({credentials});// Setup input data for the document merge processconst jsonDataForMerge = {customerName: "Kane Miller",customerVisits: 100}// Creates an asset(s) from source file(s) and uploadreadStream = fs.createReadStream("./documentMergeTemplate.docx");const inputAsset = await pdfServices.upload({readStream,mimeType: MimeType.DOCX});// Create parameters for the jobconst params = new DocumentMergeParams({jsonDataForMerge,outputFormat: OutputFormat.PDF});// Creates a new job instanceconst job = new DocumentMergeJob({inputAsset, params});// Submit the job and get the job resultconst pollingURL = await pdfServices.submit({job});const pdfServicesResponse = await pdfServices.getJobResult({pollingURL,resultType: DocumentMergeResult});// Get content from the resulting asset(s)const resultAsset = pdfServicesResponse.result.asset;const streamAsset = await pdfServices.getContent({asset: resultAsset});// Creates a write stream and copy stream asset's content to itconst outputFilePath = "./documentMergeOutput.pdf";console.log(`Saving asset at ${outputFilePath}`);const writeStream = fs.createWriteStream(outputFilePath);streamAsset.readStream.pipe(writeStream);} catch (err) {if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {console.log("Exception encountered while executing operation", err);} else {console.log("Exception encountered while executing operation", err);}} finally {readStream?.destroy();}})();
Copied to your clipboard# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples# Run the sample:# python src/documentmerge/merge_document_to_pdf.py# Initialize the loggerlogging.basicConfig(level=logging.INFO)class MergeDocumentToPDF:def __init__(self):try:file = open('./salesOrderTemplate.docx', 'rb')input_stream = file.read()file.close()# Initial setup, create credentials instancecredentials = ServicePrincipalCredentials(client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET'))# Creates a PDF Services instancepdf_services = PDFServices(credentials=credentials)# Creates an asset(s) from source file(s) and uploadinput_asset = pdf_services.upload(input_stream=input_stream,mime_type=PDFServicesMediaType.DOCX)# Setup input data for the document merge processwith open('./salesOrder.json', 'r') as file:content_string = file.read()json_data_for_merge = json.loads(content_string)# Create parameters for the jobdocument_merge_params = DocumentMergeParams(json_data_for_merge=json_data_for_merge,output_format=OutputFormat.PDF)# Creates a new job instancedocument_merge_job = DocumentMergeJob(input_asset=input_asset,document_merge_params=document_merge_params)# Submit the job and gets the job resultlocation = pdf_services.submit(document_merge_job)pdf_services_response = pdf_services.get_job_result(location, DocumentMergePDFResult)# Get content from the resulting asset(s)result_asset: CloudAsset = pdf_services_response.get_result().get_asset()stream_asset: StreamAsset = pdf_services.get_content(result_asset)# Creates an output stream and copy stream asset's content to itoutput_file_path = 'output/MergeDocumentToPDF.pdf'with open(output_file_path, "wb") as file:file.write(stream_asset.get_input_stream())except (ServiceApiException, ServiceUsageException, SdkException) as e:logging.exception(f'Exception encountered while executing operation: {e}')if __name__ == "__main__":MergeDocumentToPDF()
Copied to your clipboard// Please refer our REST API docs for more information// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generationcurl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \--header 'x-api-key: {{Placeholder for client_id}}' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer {{Placeholder for token}}' \--data-raw '{"assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718","outputFormat": "pdf","jsonDataForMerge": {"customerName": "Kane Miller","customerVisits": 100,"itemsBought": [{"name": "Sprays","quantity": 50,"amount": 100},{"name": "Chemicals","quantity": 100,"amount": 200}],"totalAmount": 300,"previousBalance": 50,"lastThreeBillings": [100,200,300],"photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="}}'
Copied to your clipboard// Please refer our REST API docs for more information// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generationcurl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \--header 'x-api-key: {{Placeholder for client_id}}' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer {{Placeholder for token}}' \--data-raw '{"input": {"uri": "https://dcplatformstorageservice-dev-us-east-1.s3-accelerate.amazonaws.com/dc-platformService-automation_dc-platformService-automation%40AdobeID/49b1d57e-23bf-4b82-a541-ba56d9b97011?X-Amz-Security-Token=FwoGZXIvYXdzEFkaDFswafxir9Mr713TUCLTAfNWbys2go%2Fmzni%2BRJvHz2rKFVfBpo%2B0R%2BowBf0Dc4TIqDAtRp%2FozbJn9qvJRkK75mSCTSWKxqGGEFowKFBQB3L2mCGDINh41F%2F0%2FQR6OswJX%2FJ4IGZPl7PrBUVv1bfNQpadx8MLfYMuJVNjGoU7MIsBMpIpDyHcRjM%2BpetRbLFtSUaD6dDCo%2BborzDaNfE%2BqFFkrwqJIe1YJkJcrABN5zYOiJPHts49YSS32jwe2%2B9awi9hesOeNSDCpoVfHi819qMCh%2FUvrKOao4MK0%2BfuPCzSEPootaLFpAYyLaqOMBNjLcQMegek%2B35KHxza2ow0U9DHrSVsxhpue53SzBU4UcOkDHBDTA7cTQ%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230620T072137Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=ASIAU5PA7W47KCSF4JF5%2F20230620%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=bc06223d01162803cc43bd8f21bddceb9377a3fab29e31ecd5c52778b528b66e","storage": "S3"},"output": {"uri": "https://dcplatformstorageservice-dev-us-east-1.s3-accelerate.amazonaws.com/dc-platformService-automation_dc-platformService-automation%40AdobeID/304625c6-f467-4c1b-bbd4-2411ad3bef06?X-Amz-Security-Token=FwoGZXIvYXdzEFkaDGn9S98klYSKO2WCGCLTAa0xfP3yS7Pz%2BaCkG8OcFbQOKSiFCSKzUbr4P%2FxMc5s3Mhd2k75p0KlBthAkrKU%2BUmbs9xZgBbDfoPeagO3sNEcbI9L1hkT%2Fgq5yoUOtekldoIHPTCrqCwrqAeV6lsGO5MnxRPFxfFVPvUfeVVL0OfmYdqKwFPe%2FJn3B4iGoJr%2B5%2BZ1JgNLXqjd1cbmCliNmOldNCdcqK2xlaqgmiFdK3wXm9cd97EnLT3UYL30MrnNjgAYu%2BTDSGFhEDO%2FmdUWQQ7RWsEq1LM5deOjWsX27tl6pxSgoj6XFpAYyLRlGz%2FpXXNuAO%2FBUkMMjIJ6NHVNTpJ0tJQcbq88Ti%2Bp5a4iu82ojskR5ehfT0g%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230620T072142Z&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Expires=3600&X-Amz-Credential=ASIAU5PA7W47L6LJD4VQ%2F20230620%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=63c7394449c51588a5bd33e2d680647c1b28f88ea5d783d75649edf96477454b","storage": "S3"},"params": {"jsonDataForMerge": {"customerName": "Kane Miller","customerVisits": 100,"itemsBought": [{"name": "Sprays","quantity": 50,"amount": 100},{"name": "Chemicals","quantity": 100,"amount": 200}],"totalAmount": 300,"previousBalance": 50,"lastThreeBillings": [100,200,300],"photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="}}}'
As a result of the Document Generation API, template tags are replaced with the input JSON data.
Generate PDF or Word document (with Fragments)
The sample below shows the use of Fragments in the word template and generates the output document in the DOCX format.
Please refer the API usage guide to understand how to use our APIs.
Copied to your clipboard// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples// Run the sample:// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.documentmerge.MergeDocumentToDOCXWithFragmentspackage com.adobe.pdfservices.operation.samples.documentmerge;public class MergeDocumentToPDFWithFragments {// Initialize the logger.private static final Logger LOGGER = LoggerFactory.getLogger(MergeDocumentToDOCXWithFragments.class);public static void main(String[] args) {try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/documentMergeFragmentsTemplate.docx").toPath())) {// Initial setup, create credentials instanceCredentials credentials = new ServicePrincipalCredentials(System.getenv("PDF_SERVICES_CLIENT_ID"),System.getenv("PDF_SERVICES_CLIENT_SECRET"));// Creates a PDF Services instancePDFServices pdfServices = new PDFServices(credentials);// Creates an asset(s) from source file(s) and uploadAsset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());// Setup input data for the document merge processJSONObject jsonDataForMerge = new JSONObject("{\n" +"\t\"customerName\": \"Kane Miller\",\n" +"\t\"customerVisits\": 100,\n" +"\t\"itemsBought\": [{\n" +"\t\t\t\"description\": \"Sprays\",\n" +"\t\t\t\"quantity\": 50,\n" +"\t\t\t\"amount\": 100\n" +"\t\t},\n" +"\t\t{\n" +"\t\t\t\"description\": \"Chemicals\",\n" +"\t\t\t\"quantity\": 100,\n" +"\t\t\t\"amount\": 200\n" +"\t\t}\n" +"\t],\n" +"\t\"totalAmount\": 300,\n" +"\t\"previousBalance\": 50,\n" +"\t\"lastThreeBillings\": [\n" +"\t\t100, 200, 300\n" +"\t],\n" +"\t\"photograph\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm6pJSdlbRoNTOEgCYJSJFVf8LDSl6A3QsEAtEnZWHq0hPzugIHZVBAqEC8fgXwFQCp7KFZR01IeI4E1OhTErvrM6UNeaqmiIDZnLmT9uwFLe6KUurbvFSnBKdpY+SoBZGLLTbi5DHwFpxPbO6SRo8um3qgCYTL6GFAoAgi8fEFIvWFQ2nhZAlC9iOIrgwKV+m5M7WLwtNSQuVz1OUbAlIlkwCSb8W2iklVEOZ8pIEibQR1kkYV1L41TBoJRJeTLOYJmWhKQKMEt/ZQoXSNEyZnlTVYkc6K6U7T6MQZTiYfipCUFGLk4+mIq3oVrLS0A7vMRD1qB5hpdipcNhaWAMCAMQW2rykroReMQKAAUu7RqEK1AlHITvQ5um4ZTFVWCA1G6exZFsohURtcun8SqsUm9V9dNNqttRNvi5TZ6f2CSoJlA2pfB+noym0TflyRlWLIlsyJEj1IoW9C0ThYujjDFuWQmObkRxHZ6ZNMa2S+m7G4ubELBhDtZU1MKXsaQdvGFbDLbXePtKj/w76hJTn6dL4M+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xkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII=\"\n" +"}");//Create fragments from fragment JSON dataJSONObject fragment1 = new JSONObject("{\n" +" \"orderDetails\":\"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"\n" +"}");JSONObject fragment2 = new JSONObject("{\n" +" \"customerDetails\":\"{{customerName}}, Visits: {{customerVisits}}\"\n" +"}");// Create Fragments ListFragments fragments = new Fragments();// Add all fragments to the created fragments listList<JSONObject> fragmentList = new ArrayList<>();fragmentList.add(fragment1);fragmentList.add(fragment2);fragments.addFragments(fragmentList);// Create parameters for the jobDocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder().withJsonDataForMerge(jsonDataForMerge).withOutputFormat(OutputFormat.DOCX).withFragments(fragments).build();// Creates a new job instanceDocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);// Submit the job and gets the job resultString location = pdfServices.submit(documentMergeJob);PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);// Get content from the resulting asset(s)Asset resultAsset = pdfServicesResponse.getResult().getAsset();StreamAsset streamAsset = pdfServices.getContent(resultAsset);// Creates an output stream and copy stream asset's content to itOutputStream outputStream = Files.newOutputStream(new File("output/documentMergeFragmentsOutput.docx").toPath());IOUtils.copy(streamAsset.getInputStream(), outputStream);outputStream.close();} catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {LOGGER.error("Exception encountered while executing operation", ex);}}}
Copied to your clipboard// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples// Run the sample:// cd MergeDocumentToDocxFragments/// dotnet run MergeDocumentToDocxFragments.csprojnamespace MergeDocumentToDocxFragments{class Program{private static readonly ILog log = LogManager.GetLogger(typeof(Program));static void Main(){//Configure the loggingConfigureLogging();try{// Initial setup, create credentials instanceICredentials credentials = new ServicePrincipalCredentials(Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));// Creates a PDF Services instancePDFServices pdfServices = new PDFServices(credentials);// Creates an asset from source file and uploadusing Stream inputStream = File.OpenRead(@"orderDetailTemplate.docx");IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.DOCX.GetMIMETypeValue());// Setup input data for the document merge processString content = File.ReadAllText(@"orderDetail.json");JObject jsonDataForMerge = JObject.Parse(content);// Fragment oneJObject obj1 =JObject.Parse("{\"orderDetails\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"}");// Fragment twoJObject obj2 = JObject.Parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}");// Fragment ObjectFragments fragments = new Fragments();// Adding Fragments to the Fragment objectfragments.AddFragment(obj1);fragments.AddFragment(obj2);// Create parameters for the jobDocumentMergeParams documentMergeParams = DocumentMergeParams.DocumentMergeParamsBuilder().WithJsonDataForMerge(jsonDataForMerge).WithOutputFormat(OutputFormat.DOCX).WithFragments(fragments).Build();// Creates a new job instanceDocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);// Submits the job and gets the job resultString location = pdfServices.Submit(documentMergeJob);PDFServicesResponse<DocumentMergeResult> pdfServicesResponse =pdfServices.GetJobResult<DocumentMergeResult>(location, typeof(DocumentMergeResult));// Get content from the resulting asset(s)IAsset resultAsset = pdfServicesResponse.Result.Asset;StreamAsset streamAsset = pdfServices.GetContent(resultAsset);// Creating output streams and copying stream asset's content to itString outputFilePath = "/output/orderDetailOutput.docx";new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create();Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath);streamAsset.Stream.CopyTo(outputStream);outputStream.Close();}catch (ServiceUsageException ex){log.Error("Exception encountered while executing operation", ex);}catch (ServiceApiException ex){log.Error("Exception encountered while executing operation", ex);}catch (SDKException ex){log.Error("Exception encountered while executing operation", ex);}catch (IOException ex){log.Error("Exception encountered while executing operation", ex);}catch (Exception ex){log.Error("Exception encountered while executing operation", ex);}}static void ConfigureLogging(){ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));}}}
Copied to your clipboard// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample// Run the sample:// node src/documentmerge/merge-document-to-pdf-fragments.jsconst {ServicePrincipalCredentials,PDFServices,MimeType,DocumentMergeParams,OutputFormat,DocumentMergeJob,DocumentMergeResult,SDKError,ServiceUsageError,ServiceApiError} = require("@adobe/pdfservices-node-sdk");const fs = require("fs");(async () => {let readStream;try {// Initial setup, create credentials instanceconst credentials = new ServicePrincipalCredentials({clientId: process.env.PDF_SERVICES_CLIENT_ID,clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET});// Creates a PDF Services instanceconst pdfServices = new PDFServices({credentials});// Creates an asset(s) from source file(s) and uploadreadStream = fs.createReadStream("./documentMergeFragmentsTemplate.docx");const inputAsset = await pdfServices.upload({readStream,mimeType: MimeType.DOCX});// Setup input data for the document merge processconst jsonDataForMerge = {customerName: 'Kane Miller',customerVisits: 100,itemsBought: [{description: 'Sprays',quantity: 50,amount: 100},{description: 'Chemicals',quantity: 100,amount: 200}],totalAmount: 300,previousBalance: 50,lastThreeBillings: [100,200,300],photograph: 'data:image/png;base64,iVBORw0K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JA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII='};// Create fragments from fragment JSON dataconst fragment1 = JSON.parse("{\"orderDetails\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"}");const fragment2 = JSON.parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}");// Create parameters for the jobconst params = new DocumentMergeParams({jsonDataForMerge,outputFormat: OutputFormat.DOCX,fragments: [fragment1, fragment2]});// Creates a new job instanceconst job = new DocumentMergeJob({inputAsset, params});// Submit the job and get the job resultconst pollingURL = await pdfServices.submit({job});const pdfServicesResponse = await pdfServices.getJobResult({pollingURL,resultType: DocumentMergeResult});// Get content from the resulting asset(s)const resultAsset = pdfServicesResponse.result.asset;const streamAsset = await pdfServices.getContent({asset: resultAsset});// Creates a write stream and copy stream asset's content to itconst outputFilePath = "./documentMergeFragmentsOutput.docx";console.log(`Saving asset at ${outputFilePath}`);const writeStream = fs.createWriteStream(outputFilePath);streamAsset.readStream.pipe(writeStream);} catch (err) {if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {console.log("Exception encountered while executing operation", err);} else {console.log("Exception encountered while executing operation", err);}} finally {readStream?.destroy();}})();
Copied to your clipboard# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples# Run the sample:# python src/documentmerge/merge_document_to_docx_with_fragments.py# Initialize the loggerlogging.basicConfig(level=logging.INFO)class MergeDocumentToDOCXWithFragments:def __init__(self):try:file = open('./documentMergeFragmentsTemplate.docx', 'rb')input_stream = file.read()file.close()# Initial setup, create credentials instancecredentials = ServicePrincipalCredentials(client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET'))# Creates a PDF Services instancepdf_services = PDFServices(credentials=credentials)# Creates an asset(s) from source file(s) and uploadinput_asset = pdf_services.upload(input_stream=input_stream,mime_type=PDFServicesMediaType.DOCX)# Setup input data for the document merge processjson_data_for_merge = {"customerName": "Kane Miller","customerVisits": 100,"itemsBought": [{"description": "Sprays","quantity": 50,"amount": 100},{"description": "Chemicals","quantity": 100,"amount": 200}],"totalAmount": 300,"previousBalance": 50,"lastThreeBillings": [100, 200, 300],"photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm6pJSdlbRoNTOEgCYJSJFVf8LDSl6A3QsEAtEnZWHq0hPzugIHZVBAqEC8fgXwFQCp7KFZR01IeI4E1OhTErvrM6UNeaqmiIDZnLmT9uwFLe6KUurbvFSnBKdpY+SoBZGLLTbi5DHwFpxPbO6SRo8um3qgCYTL6GFAoAgi8fEFIvWFQ2nhZAlC9iOIrgwKV+m5M7WLwtNSQuVz1OUbAlIlkwCSb8W2iklVEOZ8pIEibQR1kkYV1L41TBoJRJeTLOYJmWhKQKMEt/ZQoXSNEyZnlTVYkc6K6U7T6MQZTiYfipCUFGLk4+mIq3oVrLS0A7vMRD1qB5hpdipcNhaWAMCAMQW2rykroReMQKAAUu7RqEK1AlHITvQ5um4ZTFVWCA1G6exZFsohURtcun8SqsUm9V9dNNqttRNvi5TZ6f2CSoJlA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ZtwzykYNaM/B61EPwsM0LfkpzU61km3NNbpSmpnV1u5OcsOiW3tRnAINZVlWptt3g+fbnYjHeJNI/qTOUKF1pjTmTeQJjAKmUkXSMLpvip564CgxkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII="}# Create fragments from fragment JSON datafragment1 = {"orderDetails": "<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}"}fragment2 = {"customerDetails": "{{customerName}}, Visits: {{customerVisits}}"}# Create Fragments Listfragments = Fragments()fragments.add_fragment(fragment1)fragments.add_fragment(fragment2)# Create parameters for the jobdocument_merge_params = DocumentMergeParams(json_data_for_merge=json_data_for_merge,output_format=OutputFormat.DOCX,fragments=fragments)# Creates a new job instancedocument_merge_job = DocumentMergeJob(input_asset=input_asset,document_merge_params=document_merge_params)# Submit the job and gets the job resultlocation = pdf_services.submit(document_merge_job)pdf_services_response = pdf_services.get_job_result(location, DocumentMergePDFResult)# Get content from the resulting asset(s)result_asset: CloudAsset = pdf_services_response.get_result().get_asset()stream_asset: StreamAsset = pdf_services.get_content(result_asset)# Creates an output stream and copy stream asset's content to itoutput_file_path = 'output/MergeDocumentToDOCXWithFragments.pdf'with open(output_file_path, "wb") as file:file.write(stream_asset.get_input_stream())except (ServiceApiException, ServiceUsageException, SdkException) as e:logging.exception(f'Exception encountered while executing operation: {e}')if __name__ == "__main__":MergeDocumentToDOCXWithFragments()
Copied to your clipboard// Please refer our REST API docs for more information// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generationcurl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \--header 'x-api-key: {{Placeholder for client_id}}' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer {{Placeholder for token}}' \--data-raw '{"assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718","outputFormat": "docx","jsonDataForMerge": {"customerName": "Kane Miller","customerVisits": 100,"itemsBought": [{"name": "Sprays","quantity": 50,"amount": 100},{"name": "Chemicals","quantity": 100,"amount": 200}],"totalAmount": 300,"previousBalance": 50,"lastThreeBillings": [100,200,300],"photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="},"fragments": [{"orderDetails": "<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}"},{"customerDetails": "{{customerName}}, Visits: {{customerVisits}}"}]}'
Copied to your clipboard// Please refer our REST API docs for more information// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generationcurl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \--header 'x-api-key: {{Placeholder for client_id}}' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer {{Placeholder for token}}' \--data-raw '{"input": {"uri": "https://dcplatformstorageservice-dev-us-east-1.s3-accelerate.amazonaws.com/dc-platformService-automation_dc-platformService-automation%40AdobeID/49b1d57e-23bf-4b82-a541-ba56d9b97011?X-Amz-Security-Token=FwoGZXIvYXdzEFkaDFswafxir9Mr713TUCLTAfNWbys2go%2Fmzni%2BRJvHz2rKFVfBpo%2B0R%2BowBf0Dc4TIqDAtRp%2FozbJn9qvJRkK75mSCTSWKxqGGEFowKFBQB3L2mCGDINh41F%2F0%2FQR6OswJX%2FJ4IGZPl7PrBUVv1bfNQpadx8MLfYMuJVNjGoU7MIsBMpIpDyHcRjM%2BpetRbLFtSUaD6dDCo%2BborzDaNfE%2BqFFkrwqJIe1YJkJcrABN5zYOiJPHts49YSS32jwe2%2B9awi9hesOeNSDCpoVfHi819qMCh%2FUvrKOao4MK0%2BfuPCzSEPootaLFpAYyLaqOMBNjLcQMegek%2B35KHxza2ow0U9DHrSVsxhpue53SzBU4UcOkDHBDTA7cTQ%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230620T072137Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=ASIAU5PA7W47KCSF4JF5%2F20230620%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=bc06223d01162803cc43bd8f21bddceb9377a3fab29e31ecd5c52778b528b66e","storage": "S3"},"output": {"uri": "https://dcplatformstorageservice-dev-us-east-1.s3-accelerate.amazonaws.com/dc-platformService-automation_dc-platformService-automation%40AdobeID/304625c6-f467-4c1b-bbd4-2411ad3bef06?X-Amz-Security-Token=FwoGZXIvYXdzEFkaDGn9S98klYSKO2WCGCLTAa0xfP3yS7Pz%2BaCkG8OcFbQOKSiFCSKzUbr4P%2FxMc5s3Mhd2k75p0KlBthAkrKU%2BUmbs9xZgBbDfoPeagO3sNEcbI9L1hkT%2Fgq5yoUOtekldoIHPTCrqCwrqAeV6lsGO5MnxRPFxfFVPvUfeVVL0OfmYdqKwFPe%2FJn3B4iGoJr%2B5%2BZ1JgNLXqjd1cbmCliNmOldNCdcqK2xlaqgmiFdK3wXm9cd97EnLT3UYL30MrnNjgAYu%2BTDSGFhEDO%2FmdUWQQ7RWsEq1LM5deOjWsX27tl6pxSgoj6XFpAYyLRlGz%2FpXXNuAO%2FBUkMMjIJ6NHVNTpJ0tJQcbq88Ti%2Bp5a4iu82ojskR5ehfT0g%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230620T072142Z&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Expires=3600&X-Amz-Credential=ASIAU5PA7W47L6LJD4VQ%2F20230620%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=63c7394449c51588a5bd33e2d680647c1b28f88ea5d783d75649edf96477454b","storage": "S3"},"params": {"jsonDataForMerge": {"customerName": "Kane Miller","customerVisits": 100,"itemsBought": [{"name": "Sprays","quantity": 50,"amount": 100},{"name": "Chemicals","quantity": 100,"amount": 200}],"totalAmount": 300,"previousBalance": 50,"lastThreeBillings": [100,200,300],"photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="},"fragments": [{"orderDetails": "<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}"},{"customerDetails": "{{customerName}}, Visits: {{customerVisits}}"}]}}'