2026-04-18 16:02:18 +08:00
|
|
|
import type {InplaceRenderPlugin} from '../plugin.ts';
|
2025-06-30 16:12:25 +08:00
|
|
|
|
2026-04-18 16:02:18 +08:00
|
|
|
export function newInplacePluginPdfViewer(): InplaceRenderPlugin {
|
2025-06-30 16:12:25 +08:00
|
|
|
return {
|
|
|
|
|
name: 'pdf-viewer',
|
|
|
|
|
|
|
|
|
|
canHandle(filename: string, _mimeType: string): boolean {
|
|
|
|
|
return filename.toLowerCase().endsWith('.pdf');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async render(container: HTMLElement, fileUrl: string): Promise<void> {
|
2026-03-29 12:24:30 +02:00
|
|
|
const PDFObject = await import('pdfobject');
|
2025-06-30 16:12:25 +08:00
|
|
|
// TODO: the PDFObject library does not support dynamic height adjustment,
|
2026-04-18 16:02:18 +08:00
|
|
|
// TODO: it seems that this render must be an inplace render, because the URL must be accessible from the current context
|
2025-06-30 16:12:25 +08:00
|
|
|
container.style.height = `${window.innerHeight - 100}px`;
|
|
|
|
|
if (!PDFObject.default.embed(fileUrl, container)) {
|
|
|
|
|
throw new Error('Unable to render the PDF file');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|