Libraries and Frameworks
Integrations
WebViewer comes with a number of static assets such as WebAssembly modules, HTML, and CSS files. These files typically cannot be bundled with the rest your code, and therefore they need to be served statically by your web server.
Most Javascript frameworks have a public
or static
folder - a place to put assets that need to be served statically. For example, if you had a file in public/img.png
, that image would be served at /img.png
WebViewer files need to be placed in this folder so that they are served statically by your framework or server. The files that need to be copied are located in
node_modules/@pdftron/webviewer/public
if installed via NPM/lib
if you downloaded the WebViewer ZIP file manuallyAll the files in this folder need to be copied somewhere where they will be statically served. We recommend moving them into a folder called lib/webviewer
, but the actual location does not matter.
This process should always be automated as part of your build process. Below are a number of ways that you could use to achieve this.
The path
parameter of the WebViewer constructor will be set to point to the location of these static files.
The easiest way to copy the required WebViewer files is to create a script in your package.json
file that moves the necessary files into your public/static folder.
package.json
The copy-webviewer
script creates the destination folder if it does not exist and then copies the static assets into it. Please note that your folder names may vary.
Also notice that we updated our start
and build
command to first copy the WebViewer files over.
Another option is to create a script that copies the files over. This could be a node script or a shell script or whatever you choose. Below are some examples of scripts that could be used.
copy-webviewer.sh
copy-webviewer.js
Please note that it is important that the script is ran before or during your build process and before you start your dev server.
Many frameworks have plugins that can automatically copy files over during startup and during builds. The concept is the same - we need the plugin to copy the node_modules/@pdftron/webviewer/public/
assets into our static folder. Below are some examples of different plugins that we recommend.
If you are using Vite, we recommend using vite-plugin-static-copy
vite.config.js
If you are using Webpack, we recommend copy-webpack-plugin
webpack.config.js
If you are using Parcel, we recommend parcel-reporter-static-files-copy
package.json
If your build system or framework is not mentioned above, you will likely find one that works for your use case.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales