|
1 | | -import Data from '../BootstrapBlazor/modules/data.js'; |
| 1 | +import Data from '../BootstrapBlazor/modules/data.js' |
2 | 2 | import EventHandler from "../BootstrapBlazor/modules/event-handler.js" |
3 | | -import { default as EmbedPDF, UIPlugin } from './embedpdf.js'; |
| 3 | +import { default as EmbedPDF, DocumentManagerPlugin } from './embedpdf.js' |
4 | 4 | import { getTheme, registerBootstrapBlazorModule } from '../BootstrapBlazor/modules/utility.js' |
5 | 5 |
|
6 | 6 | export function init(id, invoke, options) { |
@@ -37,8 +37,21 @@ export function init(id, invoke, options) { |
37 | 37 | Data.set(id, { el, invoke, options, viewer }); |
38 | 38 | } |
39 | 39 |
|
40 | | -export function setUrl(id, url) { |
| 40 | +export async function setUrl(id, url) { |
| 41 | + if (url) { |
| 42 | + const pdf = Data.get(id); |
| 43 | + const { viewer } = pdf; |
41 | 44 |
|
| 45 | + if (viewer) { |
| 46 | + const registry = await viewer.registry; |
| 47 | + const docManager = registry.getPlugin('document-manager').provides(); |
| 48 | + docManager.openDocumentUrl({ |
| 49 | + url, |
| 50 | + documentId: getFileName(url), |
| 51 | + autoActivate: true |
| 52 | + }); |
| 53 | + } |
| 54 | + } |
42 | 55 | } |
43 | 56 |
|
44 | 57 | export function setTheme(id, theme) { |
@@ -77,3 +90,11 @@ const updateTheme = e => { |
77 | 90 | } |
78 | 91 | }); |
79 | 92 | } |
| 93 | + |
| 94 | +function getFileName(filePath) { |
| 95 | + const lastSeparatorIndex = Math.max( |
| 96 | + filePath.lastIndexOf('/'), |
| 97 | + filePath.lastIndexOf('\\') |
| 98 | + ); |
| 99 | + return filePath.substring(lastSeparatorIndex + 1); |
| 100 | +} |
0 commit comments