Loading PDFTRON Webviewer from another domain

Product: PDFTRON Webviewer

Product Version: 10.1.1

Please give a brief summary of your issue:
Unable to load pdftron webviewer from different domain

We have placed public static folder in different domain and referred the path in config. Updated config origin as specified in Apryse Documentation | Documentation. Our config file is placed in where the public root folder is placed. By doing above CORS issue resolved. However, we are unable to return the instance from config file to webviewer constructor. Is it possible to access the instance from parent which is in config file. Or is it possible, to post the instance from config file to parent.

1 Like

Hi,
Is there any update on the above request? Is it possible to access loaded instance from parent component? Please find the sample below:

Parent Component.Js:

const handleWebViewer = (params) => {
console.log(‘Handler’);
WebViewer(
{
path: “https://.amazonaws.com/pdfTron/pdfTron/",
config: "https://
.amazonaws.com/pdfTron/pdfTron/ui/configFile.js”,
fullAPI: true
},
viewer.current,
);
};

window.addEventListener('message', (event) => {
	if (event.data.type === 'webviewer-instance') {
	  // Use the received instance in the parent window
	  const webViewerInstance = event.data.instance;		  
			  console.log(webViewerInstance.getZoomLevel());
	}
  });

configFile.Js:
window.parent.postMessage({ type: ‘webviewer-instance’, instance: window.instance }, ‘*’);

1 Like

Hi @sathyavathi,

Is there a particular reason you need the instance in the WebViewer constructor when using a config file? Any code you write inside the then block of the WebViewer constructor can be run inside a config file. This includes accesing the outer page inside the config file.

Please also note that getZoomLevel is in the UI namespace so it would be called as: instance.UI.getZoomLevel()

Best Regards,
Armando Bollain
Software Developer
Apryse Software Inc.

1 Like

Thanks for the update. Instead of shifting entire logic to Configfile. Is it possible to return the loaded instance to parent where we will keep listener and keep then logic?

1 Like

Hi @sathyavathi,

That is not supported if you are running a config file. You could try updating to 10.2, which added support for Webcomponents. When using the web component there are no cross origin issues and thus a config file is not needed:

Best Regards,
Armando Bollain
Software Developer
Apryse Software Inc.

1 Like