Product
PDFTron WebViewer
Product Version
Version 11
Summary
Unable to override the default download button behavior in WebViewer v11 using UI.updateElement('downloadButton')
.
Description
When attempting to customize the download button functionality using UI.updateElement('downloadButton')
, the custom download handler is not being applied. This prevents implementing custom download logic for handling presigned URLs and specific file naming requirements.
Steps to Reproduce
- Initialize WebViewer with the following configuration:
const instance = await WebViewer({
path: "/webviewer/lib",
ui: 'legacy',
initialDoc: `/api/files/${filename}?url=${encodedUrl}&fileType=${encodedFileType}`,
enableFilePicker: false,
fullAPI: true,
enableAnnotations: true,
useDownloader: true,
backendType: 'ems',
streaming: true,
loadAsPDF: false
}, containerRef.current);
- Attempt to override the download button behavior:
instance.UI.updateElement('downloadButton', {
onClick: handleDownload
});
- Implement custom download handler:
const handleDownload = async () => {
try {
if (!documentData?.url || !documentData?.fileName) return;
const response = await fetch(documentData.url);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = documentData.fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
} catch (error) {
console.error("Download error:", error);
toast("Fehler beim Herunterladen der Datei", { position: "top-right" });
}
};
Expected Behavior
The download button should use the custom handleDownload
function when clicked, enabling custom download logic for handling presigned URLs and specific file naming.
Actual Behavior
The download button continues to use the default WebViewer download behavior instead of the custom handler.
Environment
- WebViewer Version: 11
- React Framework
- Browser: Chrome, Firefox (issue appears in all major browsers)
Additional Context
This functionality worked in previous versions of WebViewer. The custom download handler is needed to properly handle presigned URLs for cloud storage and maintain specific file naming conventions.