Support Article
Displaying a PDF using REST
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.
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/Step11520460021732.png)
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).
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/Step31520460041936.png)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/Step41520460053685.png)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/Step51520460096212.png)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/Step61520460109021.png)
//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
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.