How optimize & reduce lib folder for WebViewer when installing though NPM or remove lib folder

Product: PDFTRON In React/Next

Product Version:

@pdftron/pdfnet-node”: “^10.9.0-1”,
@pdftron/webviewer”: “8.2.0”,

How optimize & reduce lib folder for WebViewer when installing though NPM or remove lib folder

Hi we are using PDFTRON for esign and webviewer and currently webviewer has large size (277 items, totalling 74.2 MB ) as it increases the build size. How can we reduce the size or place it on different place or remove it currently.

Is there any way we can initialize the webviewr without giving the public folder path or can we use directly from the node modules so that it reduce the build size?

import WebViewer, { WebViewerInstance } from ‘@pdftron/webviewer’
WebViewer(
{
licenseKey: process.env.NEXT_PUBLIC_PDFTRON_LICENSE_KEY,
// path: ‘/webviewer/lib’, (Need to remove this line or give path for some where else so that it reduce the build size)
fullAPI: true
}

Please provide a link to a minimal sample where the issue is reproducible:(https://staging.clientpoint.me/)

Hello yashvir.singh,

As long as webviewer has access to the files when it loads, it should be fine, if you bundle your node_modules in a way that the WebViewer can access them that should be fine.

Best regards,
Tyler

@tgordon Hi can you provide us some more details, any code snippets, docs or example so that we can implement it.

Thanks
Yash

Hello yashvir.singh,

How you handle hosting of WebViewer files it up to your team, we generally recommend the public folder as it prevents any weird bundling issues.

Best regards,
Tyler

@tgordon

Here is the code snippets

WebViewer(
{
fullAPI: true,
licenseKey: xxxxxxxxxxxxxxxxxxxxxx,
path: ‘/webviewer/lib’,
css: ‘/webviewer/lib/ui/custom_pdftron.css’,
disabledElements: [
‘toolsHeader’
]
},
viewer.current
)
.then((instance) => {
instance.UI.loadDocument(getContentURL(filepath), {
extension: ‘pdf’
})
setInstanceWebViewer(instance)
})

It is inside public folder public_folder/webviewer/

We are deploying our apps on vercel and webviewer is taking alot of bandwidth so we want to remove it from public folder

Here the bandwidth details

www.testsite.net/webviewer/lib/core/office/WebOfficeWorker.br.mem
4.78 GB
dev.testsite.net/webviewer/lib/core/office/WebOfficeWorkerWasm.gz.wasm
4.57 GB

We want to reduce it by using cdn or using some other measure

Thanks
Yash

Hello yashvir.singh,

We have a guide on hosting it through CDN here: Cross-origin-workers | Apryse Documentation

Best regards,
Tyler