Friendly Filename not working for download

Posted by: jsacks on 17 August 2021, 9:56 am EST

  • Posted 17 August 2021, 9:56 am EST

    I am setting the friendly filename with viewer.options.friendlyFileName = "MyFilename.pdf" but when downloading with the toolbar Download button it gives me the original filename ("123456.pdf") from the document URL that was loaded.

    I've confirmed the viewer filename is set to the friendlyFilename by checking alert(view.fileName) in the onAfterOpen callback -- this correctly pops up "MyFilename.pdf".

    Please advise how to make the download button use the friendlyFileName (or some other way to specify the filename when this is clicked).
  • Replied 17 August 2021, 5:55 pm EST

    The friendlyFileName is used when the new document is created or when the file name is not available.

    Refer to the documentation for reference:

    Manish Gupta
  • Replied 17 August 2021, 11:51 pm EST

    Is there any way to make the file that is downloaded when clicking the Download document icon on the toolbar have a custom filename that is different from the filename of the URL that was opened in the viewer?
  • Replied 18 August 2021, 8:26 pm EST

    We are sorry for the inconvenience, we are unable to find an alternate way for this. Hence, we have forwarded this request to the concerned team for further investigation with the internal tracking id: DOC-3575.

    We will let you know as we get an update on this.

    Manish Gupta
  • Replied 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', { });
    key: "custom-download-button",
    icon: {
    type: "svg",
    content: '<svg xmlns="" 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: () => {;
    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.options.friendlyFileName = myFriendlyFileName;;
  • Replied 19 August 2021, 7:20 pm EST

    Thank you for sharing the workaround here that will be helpful to others. The issue reported to the development team has been fixed the issue internally and it will be included in the next hotfix release. We will let you know as we get an update on this,

    Manish Gupta
  • Marked as Answer

    Replied 25 September 2021, 4:01 pm EST

    This release containing this issue fix has been released with 2.2.15 version, Please upgrade it from the NPM.

    Manish Gupta
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels