Open a document by URL
Opening a document in WebViewer from URL
If you have a URL for a document, you can open it by including initialDoc as a constructor option or by using the loadDocument API.
Use the initialDoc constructor option to provide the document when mounting WebViewer.
WebViewer({
...,
initialDoc: 'https://myserver.com/myfile.pdf',
}, document.getElementById('viewer')).then(instance => {
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', () => {
// perform document operations
});
});WebViewer({
...,
initialDoc: 'https://myserver.com/myfile.pdf',
}, document.getElementById('viewer')).then(instance => {
const { docViewer } = instance;
docViewer.on('documentLoaded', () => {
// perform document operations
});
});Use loadDocument to load documents with additional loading options after mounting WebViewer.
WebViewer(...)
.then(instance => {
instance.UI.loadDocument('https://myserver.com/myfile.pdf', { filename: 'myfile.pdf' });
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', () => {
// perform document operations
});
});WebViewer(...)
.then(instance => {
instance.loadDocument('https://myserver.com/myfile.pdf', { filename: 'myfile.pdf' });
const { docViewer } = instance;
docViewer.on('documentLoaded', () => {
// perform document operations
});
});Loading Options
WebViewer provides various options to load a document. Whether you are loading a document through the initialDoc option in the constructor or calling loadDocument after mounting, you can always provide options to load your document.
Last updated
Was this helpful?