This guide will show you how to integrate WebViewer Document Viewer & Editor into an Electron desktop application.
You can also download a ready-to-go sample on GitHub.
Prior to starting, you should have already installed Node and npm.
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.
If you already have an Electron app, skip to step 2.
First, create a new folder to put our project in an navigate into it. You can use any value for the project name.
Now we can initialize our project by running the following command.
You will be asked a set of questions. There is one rule to follow for these questions:
main.js
You may enter any value for the other questions.
After answering all the questions, you should have a package.json
file in the folder you created.
Now, we can install Electron.
Now in our package.json
file, we can add a script to start Electron.
Lastly, we can create the Javascript file that will be used to run our application. Create an empty file called main.js
Now we can install WebViewer.
In addition to installing WebViewer, we will need to set up a script to copy the static WebViewer dependencies into statically served folder in your project. The reason for this is because WebViewer contains many assets that cannot be bundled by the build system. Instead, these assets need to be served statically.
In package.json
we will add a command that copies these static assets to a lib
folder. You'll also notice that we run this new command before the start command we added to ensure the files are always in the proper place when running our app.
Read more about copying WebViewer static assets.
If you already have an html file in your project, skip to step 3b.
Next, we need to create an index.html file that will be used to render our app. Create this file and add the following code.
index.html
Next, we can import the WebViewer library and create a DOM element for it to mount to.
In the <head>
block, add the following code:
Somewhere in the <body>
, create an empty div with the ID viewer
. Set the height of this div to 100vh
(if you already have your own project, you may wish to style this differently).
In our main.js
file, we can load this HTML file using the following code.
main.js
Now we are ready to initialize WebViewer. This needs to be done in a render process.
Create a file called render.js
and add the following code.
render.js
Lastly, we need to import this renderer script in our index.html
file. Add this code to the bottom of the <body>.
index.html
Now, when we run npm start
, our app should load with WebViewer displaying the default document!
View the GitHub sample to see how to add more functionality to our app. Otherwise, check out the resources below.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales