Posted 19 August 2021, 3:17 am EST
I was able to figure out an alternate way. It’s not ideal - I’d appreciate if download used viewer.fileName out of the box (not sure what viewer.fileName is actually used for in fact).
Here’s my implementation if anyone else has the same problem.
this.viewer = new GcPdfViewer('#myViewerDiv', { });
this.viewer.toolbar.addItem({
key: "custom-download-button",
icon: {
type: "svg",
content: '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path class="gc-icon-color--text" d="M5 19.998h14v-2H5m14-9h-4v-6H9v6H5l7 7 7-7z"></path></svg>'
},
title: "Download document",
checked: false,
enabled: false,
action: () => {
this.viewer.download(this.viewer.fileName);
},
onUpdate: (e) => {
return {
enabled: this.viewer.hasDocument && e.state.session.status === 3
}
}
});
this.viewer.toolbarLayout.viewer = { default: ['$navigation', '$split', 'print', '$split', '$zoom', '$split', 'doc-title'] };
this.viewer.toolbarLayout.viewer.default.splice(2, 0, "custom-download-button");
this.viewer.applyToolbarLayout();
this.viewer.options.friendlyFileName = myFriendlyFileName;
this.viewer.open(myUrlWithNastyFileName);