Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Displaying a PDF using REST

SA-53366

Summary



User needs to know how to display a PDF in base64 from a REST connector to a user.


Error Messages



Not Applicable


Steps to Reproduce



 Run a Connect-REST that returns a base64 PDF.


Root Cause



The REST connector itself will not display the PDF.  Rather, you must use an activity to take the data the REST connector provides and display it as a PDF.

Resolution



Perform the following local-change, which works for any binary file that is base-64 encoded.:

1. Map the response in the REST Connector to a Pega property.  If the response is base64, the property should be of type Text.


2. Create a new activity.  Configure the activity to display the incoming PDF in the browser.  Note, if this activity is in a different class than the Connect-REST rule or the properties the response is mapped to, you will have to configure the Pages & Classes tab and choose the appropriate step page on all steps other than Step 4 (which is always a blank step page).
               3. Configure the Parameters page exactly as shown in the image below:
4. Configure Step 1, which calls the Rest Connector, with the Connect-REST method and the ServiceName of the REST connector, similar to the example (your ServiceName will be different).  If  the REST connector needs any additional settings (for example, properties it uses to determine the endpoint URL), remember to set them earlier in the activity.
5. Configure Step 2 to map the response from the REST connector to a local variable.  Use Local.l_b64pdf as the PropertiesName.  Your PropertiesValue will vary.
6. Configure Step 3 to set the PDF document’s name.  One can also set PropertiesValue to anything – a default name (as the example below) or a dynamically generated name from a property.
7. Configure Step 4, which is Java to send the PDF to the user’s browser, exactly as follows:

//Convert the base64 PDF to a byte array

byte[] byteArray=Base64Util.decodeToByteArray(l_b64pdf);

//Get the pdf name from the parameter page

String pdfName=tools.getParamValue("PDFName");

//Send the PDF File back to the user.


String result=tools.sendFile(byteArray,pdfName,false,null,true);

8. When the activity is run, it will download the PDF from the REST connector and send it to the browser. 

By default this will display it in the browser, although browsers can override this to download it instead.

Published September 11, 2018 - Updated October 8, 2020

Was this useful?

75% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us