Can I set the filename of a PDF object displayed in Chrome?

后端 未结 2 1239
醉话见心
醉话见心 2020-11-28 10:27

In my Vue app I receive a PDF as a blob, and want to display it using the browser\'s PDF viewer.

I convert it to a file, and generate an object url:

         


        
2条回答
  •  暖寄归人
    2020-11-28 10:56

    In Chrome, the filename is derived from the URL, so as long as you are using a blob URL, the short answer is "No, you cannot set the filename of a PDF object displayed in Chrome." You have no control over the UUID assigned to the blob URL and no way to override that as the name of the page using the object element. It is possible that inside the PDF a title is specified, and that will appear in the PDF viewer as the document name, but you still get the hash name when downloading.

    This appears to be a security precaution, but I cannot say for sure.

    Of course, if you have control over the URL, you can easily set the PDF filename by changing the URL.

提交回复
热议问题