Intercept/Overwrite Download Function in WebViewer

WebViewer Version: 8.10.0

We have the use case in which the pdftron WebViewer is running in a embedded Chromium instance (CEF) .
In this case, the build in download functionality failed (not implemented). But we have the possibility, to handle a download which a custom API.

Is it possible to intercept/overwrite the download/extract functionality?

Hello,

Thank you for contacting WebViewer support.

There is an API called updateElement that you can use to override the onClick function of the download button.

You can call:

instance.UI.updateElement('downloadButton', {
    onClick: () => console.log('download button clicked'),
});

If you try the code above, you’ll notice that when you click on the download button, instead of making the download, it will just log a message. So, instead of the console.log, you’ll add your logic.

Best,

Dandara Navarro
Web Software Developer
PDFTron Systems, Inc.

Hello @dnavarro ,

thanks for your example. It works.
But there are more download related functions like the extract pages oder save as functions. This function seems to be implemented as component and generated directly while opening the context menu.

Another issue i found is, that the file-saver library seems to have some issues in sandboxed Iframes. I quess the problem is, that it try to click a generated link with a timeout (no user interaction).

Is there any way to overwrite the saveAs method or do you plan to implement something like this in the future?

Something like an optional callback function that can be added to instance.UI and which is then triggered instead of the saveAs method.

Best regards
Uli

@dnavarro I created a pull request with a example implementation.