Judson Terrell
Judson Terrell

Reputation: 4306

PDFjs custom file name with blob

I am using pdf js out of the box. The problem is that I am using a blob "blob:http://localhost:9001/12fc5fc1-bd5f-4af1-a434-0e38cb55ead"

Because of this, the url doesnt contain ".pdf" so when viewer.js parses it, it dowloads as "document.pdf"

If there anyway to use a custom file name in this situation?

Thanks

Upvotes: 1

Views: 1144

Answers (1)

Well, there are a couple of problems here:

1) When you use Blob you are pointing to an address of memory of your browser, thats the main reason you get that name. 2) to get a pdf, you should set your blob with the type of pdf, here is an example:

var blob = new Blob([data], {type: 'application/pdf'});
var url = window.URL.createObjectURL(blob);

you will get that extrange url but with a pdf extention.

The same you can do with zip or other type of file. Hope this answer helps!

Upvotes: 1

Related Questions