Expand my Community achievements bar.

workbench example of REST endpoint to create PDF from XML

Avatar

Level 1

I'm looking for a simple example of how to create a REST endpoint where I can post an xml data file over http to the LC ES2 server, and have it return the pdf file in the http response.  Does anyone have one, or know where one might be in the Adobe docs?  I haven't found it yet.  TIA.

5 Replies

Avatar

Former Community Member

How do you want to post the XML - directly from HTML, HTML through a servlet, a .Net client?

Steve

Avatar

Level 1

Direct from html will be fine.  I don't need the html example code, just how to configure within workbench.  I would like to POST two variables in the request.  First variable is the xmlData, second variable is which template (xdp) to marry with the data to generate the pdf.  The response to the request should contain the PDF file if possible.

Avatar

Former Community Member

I built a process called GetPDF that has three process variables:

1) formName - input variable of type 'string'

2) xmlDataStr - input variable of type 'string' (rather than mess with xml I just deserialize the string to xml, below)

3) pdfDoc - output variable of type 'document'

The process contains two services:

1) 'Get Form' is a Foundation Repository Service, Read Resource Content operation

Input Resource Uri - XPath expression concat("/Applications/REST-Endpoint-Sample/1.0/forms/",/process_data/@formName)

Output result - variable 'pdfDoc'

Your process may use a different technique to get the form into the process.

2) 'Render PDF Form' is a Forms FormServuce, renderPDFForm operation

Input Form - variable 'pdfDoc'

Input Form Data - XPath expression deserialize(/process_data/@xmlDataStr)

Output Rendered Form - variable 'pdfDoc'

process-map.png

Once you save, check-in, and deploy the service, go to the Administration UI > Services > Application and Services > Service Management and find the application and process. Take a look at the REST endpoint and you will see the invocation URL. In my case the URL is

http://localhost:8080/rest/services/REST-Endpoint-Sample/processes/GetPDF

Based upon the invocation URL and my process variable names, I can go to a browser and enter

http://localhost:8080/rest/services/REST-Endpoint-Sample/processes/GetPDF?formName=SimpleForm.pdf&xm... version="1.0" encoding="UTF-8"?><customer><firstName>Steve</firstName><lastName>Walker</lastName><street>345 Park Ave.</street><city>Sacramento</city><state>CA</state><zip>95829</zip></customer>

When you break down the http request you see the references to the two input variables

1) formName=SimpleForm.pdf

2) xmlDataStr=<?xml version="1.0" encoding="UTF-8"?><customer><firstName>Steve</firstName><lastName>Walker</lastName><street>345 Park Ave.</street><city>Sacramento</city><state>CA</state><zip>95829</zip></customer>

The call will result in a merged PDF document. You will notice the response URL looks something like this...

http://localhost:8080/DocumentManager/docm1268095306522/73f53c411d5ebde27161238bef2938c0?type=YXBwbG...

which is a reference to in-memory document object.

Steve

Avatar

Level 1

This works great.  I tweaked the second service a bit to use an Output - generatePDF Output service instead since that's the LC module that we are licensing.  Thanks!

Avatar

Former Community Member

Please, explain little bit more how to create first service in ES3 Workbench.

I can't find Foundation Repository Service...