---
url: /awesome-lwc-collection/components/base64ToPdf.md
description: >-
  A simple utility for Base64 encoded strings to decode and download them as PDF
  file.
---

# Base64 To PDF

A simple utility for Base64 encoded strings to decode and download them as PDF file.

**Type:** Building Block

**Available in:** App Page · Home Page · Record Page · Flow Screen

![Base64 To PDF](https://svierk.github.io/awesome-lwc-collection/images/base64ToPdf/screenshot.png)

## Read on Medium

**[How to display and download Base64 encoded PDF documents with Lightning Web Components](https://javascript.plainenglish.io/how-to-display-and-download-base64-encoded-pdf-documents-with-lightning-web-components-d4a10c7fa4c3)**

## Attributes

| Name      | Type   | Default       | Description                                                                                                                 |
| --------- | ------ | ------------- | --------------------------------------------------------------------------------------------------------------------------- |
| base64    | string |               | The content of the PDF file as Base64 encoded string, without a data URL prefix. An example file is used until this is set. |
| file-name | string | 'example.pdf' | The name of the downloaded file.                                                                                            |

## Usage

```html
<c-base64-to-pdf base64={pdfContent} file-name="invoice.pdf"></c-base64-to-pdf>
```

The content is offered as a PDF download. Without the `base64` attribute, the component offers an example file (see `example.js`). If `base64` is set but empty, for example while your data is loading, it offers no download at all.

## Custom Labels

The texts users see are Custom Labels, so they can be translated in Setup with the Translation Workbench. Copy them together with the component.

| Name                 | Value             |
| -------------------- | ----------------- |
| Base64ToPdf_Download | Download PDF File |
| Base64ToPdf_Title    | Base64 To PDF     |
