build(pdfjs-annotation-viewer): add binary font and cmap files for PDF rendering
feat(pdfjs-annotation-viewer): add various SVG icons for UI components
This commit is contained in:
@@ -13,28 +13,41 @@ export async function setupSignTool() {
|
||||
|
||||
showLoader('Loading PDF viewer...');
|
||||
|
||||
const container = document.getElementById('canvas-container-sign');
|
||||
if (container) {
|
||||
container.textContent = '';
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.width = '100%';
|
||||
iframe.style.height = '100%';
|
||||
iframe.style.border = 'none';
|
||||
container.appendChild(iframe);
|
||||
signState.viewerIframe = iframe;
|
||||
const container = document.getElementById('canvas-container-sign');
|
||||
if (container) {
|
||||
container.textContent = '';
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.width = '100%';
|
||||
iframe.style.height = '100%';
|
||||
iframe.style.border = 'none';
|
||||
container.appendChild(iframe);
|
||||
signState.viewerIframe = iframe;
|
||||
|
||||
const pdfBytes = await state.pdfDoc.save();
|
||||
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
const pdfBytes = await state.pdfDoc.save();
|
||||
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
iframe.src = `/pdfjs-viewer/viewer.html?file=${encodeURIComponent(blobUrl)}`;
|
||||
// PDF.js expects the file URL in the query string, while
|
||||
// the annotation extension reads its options from the URL hash.
|
||||
const viewerBase = '/pdfjs-annotation-viewer/web/viewer.html';
|
||||
const query = new URLSearchParams({ file: blobUrl });
|
||||
const hash = new URLSearchParams({
|
||||
// Annotation extension params (must be in the hash, not the query)
|
||||
ae_username: 'Bento User',
|
||||
ae_default_editor_active: 'true',
|
||||
ae_default_sidebar_open: 'true',
|
||||
// We intentionally do NOT set ae_post_url because Bento uses
|
||||
// client-side export only (no backend save endpoint).
|
||||
});
|
||||
|
||||
iframe.src = `${viewerBase}?${query.toString()}#${hash.toString()}`;
|
||||
|
||||
iframe.onload = () => {
|
||||
hideLoader();
|
||||
signState.viewerReady = true;
|
||||
|
||||
try {
|
||||
const viewerWindow = iframe.contentWindow;
|
||||
const viewerWindow: any = iframe.contentWindow;
|
||||
if (viewerWindow) {
|
||||
setTimeout(() => {
|
||||
const sigButton = viewerWindow.document.getElementById('editorSignature');
|
||||
@@ -45,6 +58,21 @@ export async function setupSignTool() {
|
||||
sigButtonElement.removeAttribute('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
// Make the annotation extension's "Save" button behave like
|
||||
// "Export PDF" (purely client-side) instead of POSTing to
|
||||
// ae_post_url, which we don't use in Bento.
|
||||
const ext = viewerWindow.pdfjsAnnotationExtensionInstance;
|
||||
if (ext && typeof ext.exportPdf === 'function') {
|
||||
ext.saveData = async () => {
|
||||
try {
|
||||
await ext.exportPdf();
|
||||
} catch (err) {
|
||||
console.error('Failed to export annotated PDF via Save button:', err);
|
||||
viewerWindow.alert?.('Failed to export the signed PDF. Please try again.');
|
||||
}
|
||||
};
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -62,5 +90,20 @@ export async function setupSignTool() {
|
||||
export async function applyAndSaveSignatures() {
|
||||
if (!signState.viewerReady || !signState.viewerIframe) {
|
||||
showAlert('Viewer not ready', 'Please wait for the PDF viewer to load.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const viewerWindow: any = signState.viewerIframe.contentWindow;
|
||||
if (!viewerWindow || !viewerWindow.pdfjsAnnotationExtensionInstance) {
|
||||
showAlert('Annotations not ready', 'Please wait for the annotation tools to finish loading.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger the extension's Export PDF flow so annotations are baked into the downloaded file.
|
||||
await viewerWindow.pdfjsAnnotationExtensionInstance.exportPdf();
|
||||
} catch (error) {
|
||||
console.error('Failed to export annotated PDF:', error);
|
||||
showAlert('Export failed', 'Could not export the PDF with annotations. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user