I'am able to convert my pdf files into blob. But what i want to do is the opposite by converting it from blob to pdf.
Here is my code converting it from pdf to blob. I just need some advice where i can return from blob to pdf.
var xhr=new XMLHttpRequest();
xhr.open("GET","./template.pdf");
xhr.responseType="arraybuffer";
xhr.onload = function (e){
var blob = new Blob([xhr.response]);
var url = URL.createObjectURL(blob)
console.log(url);
var embed=document.getElementById("template");
embed.src = url;
}
xhr.send();
The result will return a blob from console=> blob:http://localhost:8081/d42939da-e318-4d88-b46f-8240efaa7b1c and once i paste this on the url, it will show me a huge blob text
I'am able to convert my pdf files into blob. But what i want to do is the opposite by converting it from blob to pdf.
Here is my code converting it from pdf to blob. I just need some advice where i can return from blob to pdf.
var xhr=new XMLHttpRequest();
xhr.open("GET","./template.pdf");
xhr.responseType="arraybuffer";
xhr.onload = function (e){
var blob = new Blob([xhr.response]);
var url = URL.createObjectURL(blob)
console.log(url);
var embed=document.getElementById("template");
embed.src = url;
}
xhr.send();
The result will return a blob from console=> blob:http://localhost:8081/d42939da-e318-4d88-b46f-8240efaa7b1c and once i paste this on the url, it will show me a huge blob text
Share Improve this question asked Jan 9, 2019 at 18:56 Brandon YuBrandon Yu 591 gold badge1 silver badge5 bronze badges 1- Possible duplicate of How to go from Blob to ArrayBuffer – jtate Commented Jan 9, 2019 at 19:02
1 Answer
Reset to default 3You can set the content type when creating the blob to tell it is a pdf.
var blob = new Blob([xhr.response], { type: 'application/pdf' });