> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-a-pdf-from-a-url.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Show a PDF from a URL on a Record

Display a PDF whose address is stored on a record field, and fix a blank viewer with a checklist of the settings and source formats to verify.

Some PDFs never enter Salesforce Files: a contract stored on a document portal, a datasheet on the company website. The record holds only the address. On Northwind Fleet Renewal, the **Contract PDF URL** field holds that address, and the [PDF Viewer](https://docs.avonnicomponents.com/dynamic-components/components/pdf-viewer.md) reads it from the field. When the frame stays blank, the checklist below finds the cause.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FHL76R1GDcainALlsWwV3%2Fpdf-viewer-pdf-url-result.png?alt=media" alt="PDF Viewer showing the Master Service Agreement in Chrome&#x27;s PDF viewer on Northwind Fleet Renewal"><figcaption><p>The viewer loads the PDF at the address stored in Contract PDF URL.</p></figcaption></figure>

## Before you start

* A URL field on Opportunity to hold the address. This page uses **Contract PDF URL** (`Contract_PDF_URL__c`), filled on Northwind Fleet Renewal with an `https://` address to a PDF.
* A Dynamic Component with the **Target Page Object** set to `Opportunity`. See [Target Page Object](https://docs.avonnicomponents.com/dynamic-components/core-concepts/target-page-object.md).

## Build it

Choose how you want to build:

✨ **Build with AI**: give your AI assistant a ready-to-use prompt.

🛠️ **Build with clicks**: follow the steps in the builder yourself.

{% tabs %}
{% tab title="Build with AI" icon="wand-magic-sparkles" slug="pdf-url-build-with-ai" %}
The `avonni-dynamic-components` skill drafts the PDF Viewer bound to the record field; Salesforce must already hold the URL field and its value, and the Trusted URL if the PDF is on another site.

{% stepper %}
{% step %}

### Set up the Avonni Skills and MCP server

Follow [Setup](https://docs.avonnicomponents.com/dynamic-components/build-with-ai/setup.md) to install the Avonni Skills, connect your AI assistant to the Avonni MCP server, and sign in to your sandbox through Salesforce CLI.

Create the **Contract PDF URL** field and fill it on a test Opportunity before you prompt.
{% endstep %}

{% step %}

### Copy the prompt and review the plan

Paste the prompt into your configured assistant. Check the target org and the field mappings in its plan before you approve it.

{% prompt description="Prompt for this tutorial" icon="wand-magic-sparkles" openInAIProviders="false" defaultExpanded="partial" %}
{% code overflow="wrap" collapsedlinecount="10" %}

```
Use the avonni-dynamic-components skill. Verify the dcPdfViewer component and its placeholder properties against the Avonni MCP server (dynamic toolset) before you use any name.

Inspect my sandbox: confirm the Opportunity field Contract_PDF_URL__c exists, is a URL field, and holds an https:// address on at least one Opportunity. Tell me the domain of that address and whether a Trusted URL with the frame-src directive already covers it.

Create a Dynamic Component with Target Page Object Opportunity. Add a PDF Viewer with Source set to the current record's Contract_PDF_URL__c, Title "Contract from the document portal", Show Placeholder on with Placeholder Message "No contract link on this opportunity.", and a Height of 600px in its Size style.

Show me the plan and the field bindings before writing files. Then draft the local metadata, list what is left to set up by hand, and stop before deployment or activation.
```

{% endcode %}
{% endprompt %}
{% endstep %}

{% step %}

### Deploy to the sandbox and check the result

Review what the assistant generated and what it left for you to configure. Deploy the approved files to your sandbox only, finish any remaining setting with the **Build with clicks** tab (the Trusted URL is one of them), then check that Northwind Fleet Renewal shows the PDF from its **Contract PDF URL**.
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Build with clicks" icon="screwdriver-wrench" slug="pdf-url-build-with-clicks" %}
{% stepper %}
{% step %}

### Allow the PDF's site in a frame

Skip this step if the PDF is on your own Salesforce domain.

1. In Setup, open **Trusted URLs** and click **New Trusted URL**.
2. Enter the site's address, for example `https://docs.northwind.example`.
3. Under **CSP Directives**, check **frame-src (iframe content)**, and save.

The viewer shows the PDF in a frame, and Salesforce blocks frames from sites that are not trusted this way.
{% endstep %}

{% step %}

### Bind the viewer to the field

1. Drag a **PDF Viewer** onto the canvas.
2. Click the **Source** field and choose **$Component** > **Record** > **Contract PDF URL** (type `Contract` to filter). Source then shows the pill **Contract PDF URL**.
3. Set **Title** to `Contract from the document portal`. Screen readers announce it; it is not printed.
4. In the **Placeholder** section, turn on **Show Placeholder** and set **Placeholder Message** to `No contract link on this opportunity.` Records with an empty field show this message.
5. In the **Style** tab, under **Size**, set **Height** to `600` (unit **px**).

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FDEJ7TyTcsovRPduV1Z20%2Fpdf-viewer-pdf-url-source.png?alt=media" alt="Edit Pdf Viewer panel with the Source resource selector filtered on Contract, showing Record > Contract PDF URL (Url)" width="480"><figcaption><p>In Source, open $Component > Record and pick Contract PDF URL.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test

1. Save the component, add it to the Opportunity record page in Lightning App Builder, and open Northwind Fleet Renewal.
2. The viewer shows the PDF stored at the **Contract PDF URL** address.
3. Open Northwind Spare Parts, whose field is empty. The viewer shows "No contract link on this opportunity."

If the frame stays blank, go through the checklist below.
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## Blank viewer checklist

Work through these checks in order. The first one that fails is usually the cause.

### 1. PDFs open in the browser

For Salesforce Files, Salesforce must let PDFs open in the browser. Otherwise the frame stays blank or the file downloads.

1. In Setup, open **File Upload and Download Security** and click **Edit**.
2. Set the **.pdf** row to **Execute in Browser**.
3. Save, then reload the record page.

The [PDF Viewer](https://docs.avonnicomponents.com/dynamic-components/components/pdf-viewer.md) page shows this Setup screen.

### 2. Source is in a format the viewer recognizes

The viewer accepts four formats and leaves the frame blank, with no error, for anything else.

| Source                                                                             | Shown?                                                       |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| `069XX0000004C92AAE`, a ContentDocumentId (15 or 18 characters, starts with `069`) | Yes                                                          |
| `068XX0000004C92AAE`, a ContentVersion Id                                          | No. Use the version's **Content Document ID**.               |
| `https://docs.northwind.example/contract.pdf`                                      | Yes, if the site allows framing (check 4)                    |
| `http://docs.northwind.example/contract.pdf`                                       | Blocked by the browser on a Salesforce page. Use `https://`. |
| `docs.northwind.example/contract.pdf` or `www.northwind.example/contract.pdf`      | No. Add `https://` in front.                                 |
| `/sfc/servlet.shepherd/document/download/069...?operationContext=S1`               | Yes, a path on your Salesforce domain                        |
| `data:application/pdf;base64,JVBERi0...`                                           | Yes                                                          |
| `JVBERi0...`, Base64 without the prefix                                            | No. Add `data:application/pdf;base64,` in front.             |

To check what **Source** really receives, show the same value in a **Text** component next to the viewer for a moment.

### 3. The user can open the file

A Salesforce File follows its sharing: the viewer shows it only to users who can open it from the record. Test with the user who reports the blank frame, not as an administrator.

### 4. The site allows framing

For a PDF on another site, check its domain is in **Trusted URLs** with **frame-src (iframe content)** (step 1 of the clicks tab). Some sites refuse to be shown in a frame on any other site. That setting belongs to the site: if it refuses, upload the PDF to Salesforce Files or ask the site's owner.

## Related tutorials

* [Show the Latest Contract on an Opportunity](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-the-latest-contract-on-an-opportunity.md): show a Salesforce File instead of a URL.
* [Show a Placeholder When No PDF Is Attached](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-a-placeholder-when-no-pdf.md): more on the message shown for an empty field.
* [PDF Viewer](https://docs.avonnicomponents.com/dynamic-components/components/pdf-viewer.md): every property and source format.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-a-pdf-from-a-url.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
