首页 > 解决方案 > 下载文件和转换器以输入 doc 或 pdf

问题描述

我有一个返回 .dat 文件的 URL,我想下载它但转换为 .pdf 或 .doc 扩展名,有人可以帮我吗?

我在打字稿

网址:http ://172.17.0.53: 8060/leisarq/\originais\0000000\0000000000353.dat

标签: angulartypescriptfilepdf-conversion

解决方案


Assuming that you just want to grab the file, change the extension on the fly and save it, you can use the file-saver helper (more details here: https://www.npmjs.com/package/file-saver)

I've prepared you a simple example here:

https://stackblitz.com/edit/angular-za1kbf

The idea is quite simple, just get the original file using Angular's http.get() and finally, trigger a download on the client-side using the file-saver utility.

download() {
  return this.http.get("https://i.ibb.co/n3Y038T/a52b055eafb69acd427c99c25bc0fd02.jpg", {
      responseType: "blob"
    }).subscribe((response)=>{
     saveAs(response, "new-image.png");
  });
}

Maybe is worth to mention that this only changes the extension, the file are still a JPG (but with .PNG extension)


推荐阅读