This guide will show you how to integrate WebViewer Document Viewer & Editor into a React PDF application.
You can also download a ready-to-go sample on GitHub.
Prior to starting, you should have already installed Node and npm.
You should also have a React project to work in. If you do not have one, we recommend following our Vite guide as it is the easiest way to get started.
Get your Apryse trial key.
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
This video teaches you the fundamentals of installing and initializing WebViewer in any web application. If you wish, you may skip this section and proceed to the steps below.
Run the following command in your Terminal or Command Line:
We also have to copy the static assets required for WebViewer to run. The files are located in node_modules/@pdftron/webviewer/public
and must be moved into a location that will be served and publicly accessible. Typically, this will be a public
folder.
In package.json
we will add a command that copies these static assets to our public
folder.
package.json
You'll notice that we also updated our other scripts to run this command first - this is recommended to make sure your WebViewer assets are always in the right place.
Read more about copying static assets.
Import WebViewer into your component.
Create a reference where WebViewer will be placed or mounted.
Inside of a useEffect
hook, initialize WebViewer. Ensure that the path property in the constructor points to where you copied your static assets earlier.
React strict mode may cause undesired behaviour when working with WebViewer. Read more about common workarounds.
You can now checkout other guides like sharing WebViewer instance across components, how to open your own documents or how to disable certain features.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales