For plain JS projects, we recommend using Vite, this way you can import from module in HTML files easily:
-
Create a Vite project template:
npm create vite@latestChoose the settings:
✔ Project name: … pdfjskit-vite-example ✔ Select a framework: › Vanilla ✔ Select a variant: › JavaScript
-
A subdirectory with your project name will be created, do the following:
cd pdfjskit-vite-example npm install npm install pdfjskit
-
Edit
index.htmland replace contents with:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <title>PdfJsKit Vite Example</title> </head> <body> <div id="container"></div> <script type="module"> import PdfViewer from "pdfjskit"; var pdfViewer = new PdfViewer({ documentUrl: "pdfjskit/sample.pdf", width: "80%", height: 720, resizable: true, language: "en-US", theme: "slate, classic-dark" }); pdfViewer.render(document.getElementById("container")); </script> </body> </html>
-
Now you can run the dev web server:
npm run devwhich will show:
➜ Local: http://localhost:5173/ ➜ Network: use --host to expose ➜ press h + enter to show help
Click the Local url with CTRL key to launch the browser. You will see that PDF Viewer is rendered in the page.