0

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

Brandon Yu
  • 41
  • 1
  • 4
  • Possible duplicate of [How to go from Blob to ArrayBuffer](https://stackoverflow.com/questions/15341912/how-to-go-from-blob-to-arraybuffer) – jtate Jan 09 '19 at 19:02

1 Answers1

0

You can set the content type when creating the blob to tell it is a pdf.

var blob = new Blob([xhr.response], { type: 'application/pdf' });
Ketan Chaudhari
  • 497
  • 6
  • 15
Musa
  • 89,286
  • 16
  • 105
  • 123