WebViewer Server Not Working

Hi , I have implemented WebViewer Version but it is not working . I have implemented same as demo code

import React, { useRef, useEffect } from ‘react’
import WebViewer from ‘@pdftron/webviewer’
import ‘./DocViewer.css’
import { useSearchParams } from ‘react-router-dom’

const DocViewer = () => {
debugger
const viewer = useRef(null)
const instance = useRef()
const [searchParams] = useSearchParams()
const defaultPath = ‘/files/PDFTRON_about.pdf’
const queryPath = searchParams.get(‘path’)

var path =
queryPath === undefined || queryPath === ‘’ || queryPath == null
? defaultPath
: queryPath

// if using a class, equivalent of componentDidMount
useEffect(() => {
WebViewer(
{
// path: ‘/webviewer/lib’,
// initialDoc: path,
// fullAPI: true,

    path: '../../../lib',
    webviewerServerURL: 'https://demo.pdftron.com/',
    initialDoc:
      'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf',
  },
  viewer.current,
).then((inst) => {
  const {
    documentViewer,
    annotationManager,
    Annotations,
    Search,
  } = inst.Core
  const { Feature } = inst.UI
  inst.UI.enableFeatures([Feature.FilePicker])

  //samplesSetup(inst)
  document.getElementById('select').onchange = (e) => {
    inst.UI.loadDocument(e.target.value)
  }

  document.getElementById('file-picker').onchange = (e) => {
    const file = e.target.files[0]
    if (file) {
      inst.UI.loadDocument(file)
    }
  }

  document.getElementById('url-form').onsubmit = (e) => {
    e.preventDefault()
    inst.UI.loadDocument(document.getElementById('url').value)
  }
})

}, [path])

return (


Main Doc path : {path}



)
}

export default DocViewer

I have used below link as reference

Hi @zserviss

Can you please guide me on this?

Hi @zserviss

When I applied code for WebViewer Server on sample application it is not rendering data instead it is called multiple times

Hello akashzinzuwadia26,

I’ve tried replicating your code above and it seems that the issue might be the path property. I was able to get the same code to work using the original path: "/webviewer/lib", but I get the same issue you reported using path: "../../../lib",. Could you try editing this part to see if it fixes the issue?

Best Regards,
Carlo Mendoza
Software Developer
PDFTron Systems, Inc.