This is a simple and straightforward example of displaying a PDF inline in a Lightning Web Component.
- This collection is provided as-is. It's not officially supported by Salesforce or covered by SLAs.
- API documentation is not provided with the collection. Please refer to the official documentation.
- The documentation for the majority of the approach used here can be found in the TITLE.
- This is a teaching tool and basic example
- This is a basic proof-of-concept demonstrating that having a document such as a PDF inline in a Lightning Web Component is possible
- I did not explore and CSS or dynamic sizing capabilities although it should be possible with CSS or relative sizing parameters or through a combination of both
- For ease of deployment, I used a static resource. This could easily be adapted to use a CMS resource (either enhanced or non-enhanced). I may add that piece later.
The resource file was created like this:
- InlinePdfExampleStaticResource
- Technivorm-Moccamaster-KBG-Select-Manual.pdf
renderedCallback
function:
let renderedUrl = InlinePdfExampleStaticResource + '/Technivorm-Moccamaster-KBG-Select-Manual.pdf';
For a basic functional test, deploy the component and the static resource:
- lwc/inlinePdfViewer
- staticresources/InlinePdfExampleStaticResource
The sfdx-project.json
file contains useful configuration information for your project. See Salesforce DX Project Configuration in the Salesforce DX Developer Guide for details about this file.