Skip to content
Advertisement

How can I display a pdf with pdftron using npm

  1. pdftron/webviewer is installed

     "dependencies": {
         "@pdftron/webviewer": "^7.3.0",
         "body-parser": "^1.19.0",
         "express": "^4.17.1",
         "mongoose": "^5.9.7",
         "nodemon": "^2.0.2",
         "pug": "^2.0.4"
     }
    
  2. Webviewer static files have been copied to the public folder

  3. JavaScript in index.html file attempts to load a pdf

    Welcome to webviewer import WebViewer from ‘@/webviewer’
         WebViewer({
             path: '/webviewer',
             initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf'
         }, 
         document.getElementById('viewer')).then(instance => {})    
      </script>
    
  4. pdf file does not display, what is wrong with the code?

Advertisement

Answer

Thank-you for sharing a link to your repository.

From following this guide: https://www.pdftron.com/documentation/web/get-started/manually/

Please try doing the following:

  1. Please copy and paste webviewer.min.js from the pdftron webviewer node module to /public/webviewer

  2. in your custom.js, please remove the line that imports from webviewer

  3. in your index.html, please add this script tag before that calls your custom.js file: <script src='./webviewer/webviewer.min.js'></script>

Edit: I noticed that there is a 404 on the network tab when I load up your application which led me to think that the set up of the library was not integrated correctly.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement