PDF file download through XHR Request

前端 未结 2 640
执念已碎
执念已碎 2021-01-02 16:38

Is it totally impossible to download a pdf file through an XHR request? I know there are many other discussions already on this topic but sadly, I am still not satisfied wit

相关标签:
2条回答
  • 2021-01-02 16:54

    Have a look at this JQuery plugin jquery-file-download-plugin and here is the demo page of this plugin demo . I think its inserting iframe dynamically to DOM and produces look and feel just like AJAX request. It might be helpful for you.

    0 讨论(0)
  • 2021-01-02 17:07

    It certainly depends on the size of the PDF file, but this would be a workable approach if the PDF isn't too large:

    1. Show the "waiting image" and download the PDF using $http.

      $http.get('http://my.example.com/foo.pdf').success(function(pdfData) {
        ... do something with pdfData ...
      });
      
    2. Convert pdfData to Base64 encoding and use a data URI scheme to create a URL for the downloaded PDF file.

    3. Redirect to that URL.
    0 讨论(0)
提交回复
热议问题