PDF Viewer
Overview
The Avonni PDF Viewer component allows you to embed and display PDF documents directly within your Dynamic Components on Salesforce Lightning Pages. This provides a seamless way for users to view PDF content —such as invoices, contracts, reports, or guides —without downloading the file or opening a separate application.
Key features include:
Direct PDF Embedding: Displays PDF content directly on the Lightning Page.
Multiple Source Options: Load PDFs from Salesforce Files (using ContentDocumentId), external URLs, or base64-encoded data.
Simple Configuration: Requires minimal setup, primarily involving the definition of the PDF source.

Salesforce setting required for inline PDF viewing
In Salesforce Setup, go to “File Upload and Download Security.” Find the entry for PDF and set its behavior to “Execute in Browser.” This enables the PDF to render inside the component. If it’s set to “Download,” Salesforce will force the file to download, and the viewer will appear blank or trigger a download rather than display the document.
How to check and update:
Setup → Quick Find: “File Upload and Download Security”
Open the list, locate “PDF”
Change Behavior to “Execute in Browser”
Save
Refresh your Lightning page and test the viewer
Use Cases
Displaying generated invoice or quote PDFs on Opportunity or Order records.
Showing signed contracts or agreements on Account or Contact pages.
Embedding product manuals or datasheets on Product record pages.
Presenting reports generated as PDFs within a dashboard component.
Viewing uploaded attachments directly within a custom component context.
Adding the PDF Viewer
Drag and Drop: From the Component Library (left panel), find the "PDF Viewer" component and drag it onto your canvas within the Component Builder.
Configuration
Select the PDF Viewer component on the canvas to access its properties in the Properties Panel.
Basic Properties
API Name: (Text) A unique identifier for this component instance (e.g.,
InvoiceViewer,ContractDisplay).Title: (Text, Optional) A title displayed potentially above or as part of the viewer's frame (depending on styling). Example: "Invoice Preview", "Contract Document".
PDF Source
Source: (Text - Essential) This critical property indicates the origin of the PDF document. You must provide the source in one of the following formats:
ContentDocumentId: Provide the 15 or 18-character Salesforce ID of a File (ContentDocument record) stored within your Salesforce org. This is the most common and recommended method for securely displaying internal documents. You will typically bind this property to a Variable or resource holding the ID (e.g.,
{!FileIdVariable},$Component.record.LatestInvoiceId__c).URL: Provide a direct, publicly accessible HTTPS URL pointing to a PDF file hosted online (e.g.,
https://example.com/document.pdf). Ensure the URL is correct and that your users have access to it, taking into account potential network restrictions or CORS issues.Base64: Provide a Base64-encoded string representing the entire content of the PDF file. This method is generally only suitable for small PDFs that might be generated dynamically or passed from another system. Large Base64 strings can significantly impact performance and may hit component configuration size limits.
Set Component Visibility
Controls whether the PDF Viewer component is displayed on the page. Bind this to a Boolean Variable or Formula for dynamic visibility.
Examples
Displaying a Salesforce File (using ContentDocumentId)
Scenario: Display the latest invoice PDF related to the current Opportunity record page.
Approach: Use an autolaunched Flow triggered "On Load" to retrieve the ContentDocumentId and pass it to the PDF Viewer.
Setup Overview
Create an Autolaunched Flow
Since the PDF Viewer component requires a ContentDocumentId to display a Salesforce file, but you typically only have access to the record ID (e.g., Opportunity ID), you need a way to find the correct file. An Autolaunched Flow allows you to:
Query the Salesforce database to find files related to the current record
Apply filters to locate the specific PDF you want to display (e.g., the latest invoice)
Return the
ContentDocumentIdto the component
Configuration
Accepts the record ID as input
Queries related files through
ContentDocumentLinkandContentVersionobjectsFilters for PDF files with "Invoice" in the title
Returns the
ContentDocumentIdof the most recent matching file
In your Dynamic Component
Now that your Flow is ready to retrieve the ContentDocumentId, you need to configure your Dynamic Component to execute this Flow and pass the result to the PDF Viewer. This involves setting the target object, creating a variable to store the file ID, triggering the Flow when the page loads, and binding that variable to the PDF Viewer's Source property.
Steps:
Set the Target Object Name to
Opportunityin your Dynamic Component settings (this enables access to the current record context)Create a Text Variable (e.g.,
invoiceFileId) to store the ContentDocumentIdAdd an Execute Flow action to the On Load interaction:
Select your autolaunched Flow
Map the Flow's input variable to
@recordId(this passes the current Opportunity ID to the Flow)Map the Flow's output variable to
{!invoiceFileId}(this stores the returned ContentDocumentId)
Configure the PDF Viewer's Source property to
{!invoiceFileId}
Result: When the page loads, the Flow retrieves the latest invoice PDF's ContentDocumentId and the PDF Viewer displays it automatically.
Displaying a PDF from an External URL
Scenario: Embed a publicly available product datasheet PDF.
Add PDF Viewer: Add the component to your canvas.
Configure Source:
Select the PDF Viewer.
In the
Sourceproperty, directly enter the full HTTPS URL of the PDF file (e.g.,https://www.example-company.com/datasheets/product-xyz.pdf). You can also bind this to a Text Variable or Constant resource that holds the URL.
Set Title (Optional): Set the
Titleproperty (e.g., "Product XYZ Datasheet").
Key Considerations
Permissions (Salesforce Files): If using
ContentDocumentId, ensure users viewing the page have the necessary Salesforce permissions to access that specific File record.URL Accessibility: If using a
URL, verify the URL is correct, publicly accessible (or accessible within the user's network), and consider potential Cross-Origin Resource Sharing (CORS) restrictions that might prevent embedding. Use HTTPS.⚠️ Salesforce File Handling Setting: In Salesforce Setup, navigate to "File Upload and Download Security". Ensure the behavior for PDF files is set to "Execute in Browser". If it is configured as "Download", this component may not display the PDF inline and may instead trigger a file download.

Base64 Performance/Limits: Avoid using Base64 for large PDFs due to performance impacts and potential size limitations.
ContentDocumentIdorURLare generally preferred.Browser Compatibility: PDF rendering relies on browser capabilities or built-in PDF viewers. Ensure compatibility with your users' standard browsers
URL Display Restrictions & Workaround
When using a direct URL as the PDF source, be aware that Salesforce security settings or browser policies might sometimes prevent the PDF from displaying correctly within the PDF Viewer. In such cases, users may encounter a blank frame or an error message.
Workaround: Embed using Google Docs Viewer
To bypass these restrictions, you can leverage the Google Docs Viewer service, which allows PDF files to be displayed within an iframe, even if the original file's direct embedding is blocked.
How to Use:
Set the Source property of the PDF Viewer to a Google Docs Viewer link structured as follows (can be done using a formula text variable)
Example:
⚠️ Important
To allow this workaround, ensure that https://docs.google.com is added to your list of Trusted URLs in Salesforce Setup, and that docs.google.com is authorized for iframe usage within your org's security policies.
In Summary
The Avonni PDF Viewer component offers a straightforward way to display PDF documents from various sources directly within your custom Lightning Page interfaces, thereby enhancing users' access to contextual information.
Last updated
Was this helpful?
