We recommend the Overview page to learn how to correctly use a config.js
before getting started with using Webviewer.
To convert a document, first you'll need to open a document in our lightning web componenet where the Webviewer is mounted in an iFrame (in our sample, it is pdftronWvInstance
).
Once a document is loaded and viewable in our preview screen, you'll be allowed to convert documents in our available formats:
We store the open document into an object and label it as payload
. Storing the neccessary information for conversion and saving the converted file onto salesforce.
Since WebViewer is hosted in an iFrame, we need to use our config.js
file to access our WebViewer instance. You need to post a message to your iframeWindow
like so:
In a Salesforce deployment, the equivalent of instance
is readerControl
.
In your config.js
file, you can you listen for messages posted to the iFrame by registering an event listener using window.addEventListener("message", this.handleReceiveMessage)
. In this case, handleReceiveMessage
is a function that handles these posted messages. You can review the snippet below for an example of how to deal with posted messages.
This snippet uses the instance of Webviewer and converts the loaded document as a PDF. When downloaded, we are allowed to download from the instance using our API call downloadPdf()
. Writing to Salesforce we have to grab file data and return the converted data back to the lwc with a event listener.
Similar to standard conversion to pdf, all conversions including pdf to image files would converted in config.js
file.
The following snippet uses multiple namespaces in our API:
You can review the Salesforce PDF App to showcase an end-to-end example of document conversion in Github repository.
Check out this live file conversion demo (hosted outside of Salesforce).
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales