> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Taking Base64 Encoded PDF Data from Json Content, Decoding It, and Returning It to Be Displayed or Downloaded in Browser

> Decoding PDF content encoded as base64 in service response with Groovy script and returning it to be displayed or downloadable in browser

## Example Response Data

```json theme={null}
{"pdf":"<BASE64_ENCODED_DATA>"}
```

## Displaying in Browser

```groovy theme={null}
import groovy.json.JsonSlurper
import java.util.Base64

def slurper = new JsonSlurper()
def parsedJson = slurper.parseText(responseBodyTextFromTargetAPI)
def pdfAsBase64 = parsedJson.data;

responseBodyTextToClient = new String(Base64.decoder.decode(pdfAsBase64), "UTF-8")
responseHeaderMapToClient.put("Content-Type", "application/pdf")
responseHeaderMapToClient.put("Content-Disposition", "inline")
```

<Warning>
  Not every web browser may provide this display.
</Warning>

## PDF Download Operation

```groovy theme={null}
import groovy.json.JsonSlurper
import java.util.Base64

def slurper = new JsonSlurper()
def parsedJson = slurper.parseText(responseBodyTextFromTargetAPI)
def pdfAsBase64 = parsedJson.data;

responseBodyTextToClient = new String(Base64.decoder.decode(pdfAsBase64), "UTF-8")
responseHeaderMapToClient.put("Content-Type", "application/pdf")
responseHeaderMapToClient.put("Content-Disposition", "attachment")
```

<Note>
  In both operations, it should be verified that the PDF content is reflected correctly. This script should be run on the response line (Response Policy).
</Note>
