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 clipboard1{2 "Client" : {3 "Name" : "Some Corp Inc",4 "Address" : "Somewhere Street"5 }6}
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 clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.documentmerge.MergeDocumentToPDF45 package com.adobe.pdfservices.operation.samples.documentmerge;67 public class MergeDocumentToPDF {89 // Initialize the logger.10 private static final Logger LOGGER = LoggerFactory.getLogger(MergeDocumentToPDF.class);1112 public static void main(String[] args) {1314 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/documentMergeTemplate.docx").toPath())) {15 // Initial setup, create credentials instance16 Credentials credentials = new ServicePrincipalCredentials(17 System.getenv("PDF_SERVICES_CLIENT_ID"),18 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1920 // Creates a PDF Services instance21 PDFServices pdfServices = new PDFServices(credentials);2223 // Setup input data for the document merge process.24 JSONObject jsonDataForMerge = new JSONObject("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}");2526 // Creates an asset(s) from source file(s) and upload27 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());2829 // Create parameters for the job30 DocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder()31 .withJsonDataForMerge(jsonDataForMerge)32 .withOutputFormat(OutputFormat.PDF)33 .build();3435 // Creates a new job instance36 DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);3738 // Submit the job and gets the job result39 String location = pdfServices.submit(documentMergeJob);40 PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);4142 // Get content from the resulting asset(s)43 Asset resultAsset = pdfServicesResponse.getResult().getAsset();44 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4546 // Creates an output stream and copy stream asset's content to it47 OutputStream outputStream = Files.newOutputStream(new File("output/documentMergeOutput.pdf").toPath());48 IOUtils.copy(streamAsset.getInputStream(), outputStream);49 outputStream.close();50 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {51 LOGGER.error("Exception encountered while executing operation", ex);52 }53 }54 }55
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd MergeDocumentToPDF/4// dotnet run MergeDocumentToPDF.csproj56 namespace MergeDocumentToPDF7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));1112 static void Main()13 {14 //Configure the logging.15 ConfigureLogging();16 try17 {18 // Initial setup, create credentials instance.19 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()20 .WithClientId("PDF_SERVICES_CLIENT_ID")21 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")22 .Build();2324 // Create an ExecutionContext using credentials.25 ExecutionContext executionContext = ExecutionContext.Create(credentials);2627 // Setup input data for the document merge process.28 JObject jsonDataForMerge = JObject.Parse("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}");2930 // Create a new DocumentMerge Options instance.31 DocumentMergeOptions documentMergeOptions = new DocumentMergeOptions(jsonDataForMerge, OutputFormat.PDF);3233 // Create a new DocumentMerge Operation instance with the DocumentMerge Options instance.34 DocumentMergeOperation documentMergeOperation = DocumentMergeOperation.CreateNew(documentMergeOptions);3536 // Set the operation input document template from a source file.37 documentMergeOperation.SetInput(FileRef.CreateFromLocalFile(@"documentMergeTemplate.docx"));3839 // Execute the operation.40 FileRef result = documentMergeOperation.Execute(executionContext);4142 // Save the result to the specified location.43 result.SaveAs(Directory.GetCurrentDirectory() + "/output/documentMergeOutput.pdf");44 }45 catch (ServiceUsageException ex)46 {47 log.Error("Exception encountered while executing operation", ex);48 }49 catch (ServiceApiException ex)50 {51 log.Error("Exception encountered while executing operation", ex);52 }53 catch (SDKException ex)54 {55 log.Error("Exception encountered while executing operation", ex);56 }57 catch (IOException ex)58 {59 log.Error("Exception encountered while executing operation", ex);60 }61 catch (Exception ex)62 {63 log.Error("Exception encountered while executing operation", ex);64 }65 }6667 static void ConfigureLogging()68 {69 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());70 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));71 }72 }73 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/documentmerge/merge-document-to-pdf.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 DocumentMergeParams,10 OutputFormat,11 DocumentMergeJob,12 DocumentMergeResult,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Setup input data for the document merge process32 const jsonDataForMerge = {33 customerName: "Kane Miller",34 customerVisits: 10035 }3637 // Creates an asset(s) from source file(s) and upload38 readStream = fs.createReadStream("./documentMergeTemplate.docx");39 const inputAsset = await pdfServices.upload({40 readStream,41 mimeType: MimeType.DOCX42 });4344 // Create parameters for the job45 const params = new DocumentMergeParams({46 jsonDataForMerge,47 outputFormat: OutputFormat.PDF48 });4950 // Creates a new job instance51 const job = new DocumentMergeJob({inputAsset, params});5253 // Submit the job and get the job result54 const pollingURL = await pdfServices.submit({job});55 const pdfServicesResponse = await pdfServices.getJobResult({56 pollingURL,57 resultType: DocumentMergeResult58 });5960 // Get content from the resulting asset(s)61 const resultAsset = pdfServicesResponse.result.asset;62 const streamAsset = await pdfServices.getContent({asset: resultAsset});6364 // Creates a write stream and copy stream asset's content to it65 const outputFilePath = "./documentMergeOutput.pdf";66 console.log(`Saving asset at ${outputFilePath}`);6768 const writeStream = fs.createWriteStream(outputFilePath);69 streamAsset.readStream.pipe(writeStream);70 } catch (err) {71 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {72 console.log("Exception encountered while executing operation", err);73 } else {74 console.log("Exception encountered while executing operation", err);75 }76 } finally {77 readStream?.destroy();78 }79})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generation34curl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "outputFormat": "pdf",11 "jsonDataForMerge": {12 "customerName": "Kane Miller",13 "customerVisits": 100,14 "itemsBought": [15 {16 "name": "Sprays",17 "quantity": 50,18 "amount": 10019 },20 {21 "name": "Chemicals",22 "quantity": 100,23 "amount": 20024 }25 ],26 "totalAmount": 300,27 "previousBalance": 50,28 "lastThreeBillings": [29 100,30 200,31 30032 ],33 "photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="34 }35}'
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generation34curl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "input": {10 "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",11 "storage": "S3"12 },13 "output": {14 "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",15 "storage": "S3"16 },17 "params": {18 "jsonDataForMerge": {19 "customerName": "Kane Miller",20 "customerVisits": 100,21 "itemsBought": [22 {23 "name": "Sprays",24 "quantity": 50,25 "amount": 10026 },27 {28 "name": "Chemicals",29 "quantity": 100,30 "amount": 20031 }32 ],33 "totalAmount": 300,34 "previousBalance": 50,35 "lastThreeBillings": [36 100,37 200,38 30039 ],40 "photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="41 }42 }43}'
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 clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.documentmerge.MergeDocumentToDOCXWithFragments4 package com.adobe.pdfservices.operation.samples.documentmerge;56 public class MergeDocumentToPDFWithFragments {78 // Initialize the logger.9 private static final Logger LOGGER = LoggerFactory.getLogger(MergeDocumentToDOCXWithFragments.class);1011 public static void main(String[] args) {1213 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/documentMergeFragmentsTemplate.docx").toPath())) {14 // Initial setup, create credentials instance15 Credentials credentials = new ServicePrincipalCredentials(16 System.getenv("PDF_SERVICES_CLIENT_ID"),17 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1819 // Creates a PDF Services instance20 PDFServices pdfServices = new PDFServices(credentials);2122 // Creates an asset(s) from source file(s) and upload23 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());2425 // Setup input data for the document merge process26 JSONObject jsonDataForMerge = new JSONObject("{\n" +27 "\t\"customerName\": \"Kane Miller\",\n" +28 "\t\"customerVisits\": 100,\n" +29 "\t\"itemsBought\": [{\n" +30 "\t\t\t\"description\": \"Sprays\",\n" +31 "\t\t\t\"quantity\": 50,\n" +32 "\t\t\t\"amount\": 100\n" +33 "\t\t},\n" +34 "\t\t{\n" +35 "\t\t\t\"description\": \"Chemicals\",\n" +36 "\t\t\t\"quantity\": 100,\n" +37 "\t\t\t\"amount\": 200\n" +38 "\t\t}\n" +39 "\t],\n" +40 "\t\"totalAmount\": 300,\n" +41 "\t\"previousBalance\": 50,\n" +42 "\t\"lastThreeBillings\": [\n" +43 "\t\t100, 200, 300\n" +44 "\t],\n" +45 "\t\"photograph\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm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omi8oi/zSaG/isLO4URFM4PUm/aUpeAcG04+qd+gcgTcRh3jkaU1A1MrgNMlGpl8VK8Z/zUWUcyEZRFNpB47Go0pDdVa3ByjdZSK1MMWhJUI8PuiPPu0XM3Onaib4Q062OuOrM0Cc8Iak7VxPhB84asv7ctoRYQ56EKxyeBhprIZ8WPsnSB3SK5LSYrkhySns/QKXoffBt7m7giZtWw+2xgzTyjEl1N91P67yInyLLe4qA/P2I+z5oSkRl6Rsk/Zo6PRShOHQXcTZYom2TrXFicUVbtMEa1sK3Rqch5hRStOM/MmjsDtiSovXDTDLQuGFGvrmJUxIi5OiBFc4GmornWp732Fmn+S2mr/fXNhmXIzHj9SOoz0nqrNdsR3k10QTo6EtI6IKVzpGGixvRZyu6YMZs0G58hv4gOdqCOUeVmKLJu5aMjyQmkZtwzykYNaM/B61EPwsM0LfkpzU61km3NNbpSmpnV1u5OcsOiW3tRnAINZVlWptt3g+fbnYjHeJNI/qTOUKF1pjTmTeQJjAKmUkXSMLpvip564CgxkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII=\"\n" +46 "}");4748 //Create fragments from fragment JSON data49 JSONObject fragment1 = new JSONObject("{\n" +50 " \"orderDetails\":\"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"\n" +51 "}");52 JSONObject fragment2 = new JSONObject("{\n" +53 " \"customerDetails\":\"{{customerName}}, Visits: {{customerVisits}}\"\n" +54 "}");5556 // Create Fragments List57 Fragments fragments = new Fragments();5859 // Add all fragments to the created fragments list60 List<JSONObject> fragmentList = new ArrayList<>();61 fragmentList.add(fragment1);62 fragmentList.add(fragment2);63 fragments.addFragments(fragmentList);6465 // Create parameters for the job66 DocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder()67 .withJsonDataForMerge(jsonDataForMerge)68 .withOutputFormat(OutputFormat.DOCX)69 .withFragments(fragments)70 .build();7172 // Creates a new job instance73 DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);7475 // Submit the job and gets the job result76 String location = pdfServices.submit(documentMergeJob);77 PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);7879 // Get content from the resulting asset(s)80 Asset resultAsset = pdfServicesResponse.getResult().getAsset();81 StreamAsset streamAsset = pdfServices.getContent(resultAsset);8283 // Creates an output stream and copy stream asset's content to it84 OutputStream outputStream = Files.newOutputStream(new File("output/documentMergeFragmentsOutput.docx").toPath());85 IOUtils.copy(streamAsset.getInputStream(), outputStream);86 outputStream.close();87 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {88 LOGGER.error("Exception encountered while executing operation", ex);89 }90 }91 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd MergeDocumentToDocx/4// dotnet run MergeDocumentToDocxFragments.csproj5 namespace MergeDocumentToDocxFragments6 {7 class Program8 {9 private static readonly ILog log = LogManager.GetLogger(typeof(Program));1011 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 // Create an ExecutionContext using credentials.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);2526 // Setup input data for the document merge process27 var content = File.ReadAllText(@"orderDetail.json");28 JObject jsonDataForMerge = JObject.Parse(content);2930 // Fragment one31 JObject obj1 = JObject.Parse("{\"orderDetails\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"}");3233 // Fragment two34 JObject obj2 = JObject.Parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}");3536 // Fragment Object37 Fragments fragments = new Fragments();3839 // Adding Fragments to the Fragment object40 fragments.AddFragment(obj1);41 fragments.AddFragment(obj2);42434445 // Create a new DocumentMerge Options instance with fragment46 DocumentMergeOptions documentMergeOptions = new DocumentMergeOptions(jsonDataForMerge, OutputFormat.DOCX, fragments);4748 // Create a new DocumentMerge Operation instance with the DocumentMerge Options instance49 DocumentMergeOperation documentMergeOperation = DocumentMergeOperation.CreateNew(documentMergeOptions);5051 // Set the operation input document template from a source file.52 documentMergeOperation.SetInput(FileRef.CreateFromLocalFile(@"orderDetailTemplate.docx"));5354 // Execute the operation.55 FileRef result = documentMergeOperation.Execute(executionContext);5657 // Save the result to the specified location58 result.SaveAs(Directory.GetCurrentDirectory() + "/output/orderDetailOutput.docx");59 }60 catch (ServiceUsageException ex)61 {62 log.Error("Exception encountered while executing operation", ex);63 }64 catch (ServiceApiException ex)65 {66 log.Error("Exception encountered while executing operation", ex);67 }68 catch (SDKException ex)69 {70 log.Error("Exception encountered while executing operation", ex);71 }72 catch (IOException ex)73 {74 log.Error("Exception encountered while executing operation", ex);75 }76 catch (Exception ex)77 {78 log.Error("Exception encountered while executing operation", ex);79 }80 }8182 static void ConfigureLogging()83 {84 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());85 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));86 }87 }88 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/documentmerge/merge-document-to-pdf-fragments.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 DocumentMergeParams,10 OutputFormat,11 DocumentMergeJob,12 DocumentMergeResult,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./documentMergeFragmentsTemplate.docx");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.DOCX36 });3738 // Setup input data for the document merge process39 const jsonDataForMerge = {40 customerName: 'Kane Miller',41 customerVisits: 100,42 itemsBought: [43 {44 description: 'Sprays',45 quantity: 50,46 amount: 10047 },48 {49 description: 'Chemicals',50 quantity: 100,51 amount: 20052 }53 ],54 totalAmount: 300,55 previousBalance: 50,56 lastThreeBillings: [57 100,58 200,59 30060 ],61 photograph: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZuElEQVR4nL1de7gcRZX/neqeme65l7zuzRsijxgwBJJAghBBXQ0PkeCCD15+i+7qqkvg81v8dkX9Y1fYBZUVBVzQRR4rEXCVh8AniisQFJIQlIsIeQAxkoQ8bp7ce+fR3XX2j+ruqZ7q7um5N+z55ruZ6T516lTVr845daq6Q+sO6Z0B8hkABBRJAAKEiNR1otYVnYi178QxJzOn8kecLR7mlmROryTklIkrFPNLg1+ivXbFybJVu8/t5fRSUteEBTPb2c0ZDYWNBwBktDrilIozj1dJyxqk0emm6pJSdlbRoNTOEgCYJSJFVf8LDSl6A3QsEAtEnZWHq0hPzugIHZVBAqEC8fgXwFQCp7KFZR01IeI4E1OhTErvrM6UNeaqmiIDZnLmT9uwFLe6KUurbvF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0XM3Onaib4Q062OuOrM0Cc8Iak7VxPhB84asv7ctoRYQ56EKxyeBhprIZ8WPsnSB3SK5LSYrkhySns/QKXoffBt7m7giZtWw+2xgzTyjEl1N91P67yInyLLe4qA/P2I+z5oSkRl6Rsk/Zo6PRShOHQXcTZYom2TrXFicUVbtMEa1sK3Rqch5hRStOM/MmjsDtiSovXDTDLQuGFGvrmJUxIi5OiBFc4GmornWp732Fmn+S2mr/fXNhmXIzHj9SOoz0nqrNdsR3k10QTo6EtI6IKVzpGGixvRZyu6YMZs0G58hv4gOdqCOUeVmKLJu5aMjyQmkZtwzykYNaM/B61EPwsM0LfkpzU61km3NNbpSmpnV1u5OcsOiW3tRnAINZVlWptt3g+fbnYjHeJNI/qTOUKF1pjTmTeQJjAKmUkXSMLpvip564CgxkYzytEgnRg23ydEpo3b1RGKW9YF+at9cxmmTV2h+vEOcFRiq6LiI1EqnDv8DFMX/p0qKgIStifo5R1xKkEmJjE07Zxj+dR7nIFoiIDwHz2TaDjO/Eyqh25HE/w/Y7omSZoG071FjIqYieEnAItdnhRdSsKOxal2Q3Itsr0WnsZ3PaqEjxRPpJA2LUDxvNUrOwtjRqcMpGmYwWBrQynr5UiKMyEdHRjGKDs20sURrfeTZmkQB9fSyD0CGW7MGSDKsT0vvdi/ZrrTuSTORlZPSb1kSbSlQ3IvlPMAYqpv9liwTOwHZ6IRrRbr10aVJQQCsDAG6tv8HcAoVaSJluIMAAAAASUVORK5CYII='62 };6364 // Create fragments from fragment JSON data65 const fragment1 = JSON.parse("{\"orderDetails\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}\"}");66 const fragment2 = JSON.parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}");6768 // Create parameters for the job69 const params = new DocumentMergeParams({70 jsonDataForMerge,71 outputFormat: OutputFormat.DOCX,72 fragments: [fragment1, fragment2]73 });7475 // Creates a new job instance76 const job = new DocumentMergeJob({inputAsset, params});7778 // Submit the job and get the job result79 const pollingURL = await pdfServices.submit({job});80 const pdfServicesResponse = await pdfServices.getJobResult({81 pollingURL,82 resultType: DocumentMergeResult83 });8485 // Get content from the resulting asset(s)86 const resultAsset = pdfServicesResponse.result.asset;87 const streamAsset = await pdfServices.getContent({asset: resultAsset});8889 // Creates a write stream and copy stream asset's content to it90 const outputFilePath = "./documentMergeFragmentsOutput.docx";91 console.log(`Saving asset at ${outputFilePath}`);9293 const writeStream = fs.createWriteStream(outputFilePath);94 streamAsset.readStream.pipe(writeStream);95 } catch (err) {96 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {97 console.log("Exception encountered while executing operation", err);98 } else {99 console.log("Exception encountered while executing operation", err);100 }101 } finally {102 readStream?.destroy();103 }104})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generation34curl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "outputFormat": "docx",11 "jsonDataForMerge": {12 "customerName": "Kane Miller",13 "customerVisits": 100,14 "itemsBought": [15 {16 "name": "Sprays",17 "quantity": 50,18 "amount": 10019 },20 {21 "name": "Chemicals",22 "quantity": 100,23 "amount": 20024 }25 ],26 "totalAmount": 300,27 "previousBalance": 50,28 "lastThreeBillings": [29 100,30 200,31 30032 ],33 "photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="34 },35 "fragments": [36 {37 "orderDetails": "<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}"38 },39 {40 "customerDetails": "{{customerName}}, Visits: {{customerVisits}}"41 }42 ]43}'
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Document-Generation34curl --location --request POST 'https://pdf-services.adobe.io/operation/documentgeneration' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "input": {10 "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",11 "storage": "S3"12 },13 "output": {14 "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",15 "storage": "S3"16 },17 "params": {18 "jsonDataForMerge": {19 "customerName": "Kane Miller",20 "customerVisits": 100,21 "itemsBought": [22 {23 "name": "Sprays",24 "quantity": 50,25 "amount": 10026 },27 {28 "name": "Chemicals",29 "quantity": 100,30 "amount": 20031 }32 ],33 "totalAmount": 300,34 "previousBalance": 50,35 "lastThreeBillings": [36 100,37 200,38 30039 ],40 "photograph": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88h8AAu0B9XNPCQQAAAAASUVORK5CYII="41 },42 "fragments": [43 {44 "orderDetails": "<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{amount}}"45 },46 {47 "customerDetails": "{{customerName}}, Visits: {{customerVisits}}"48 }49 ]50 }51}'