Skip to content Skip to sidebar Skip to footer

How To Convert Byte Array To Pdf And Download

I am trying to do a simple task of downloading a http response to a pdf. I am generating a pdf file but I am getting an error of 'Failed to open PDF'. Here is what the response loo

Solution 1:

If anyone looking for solution with same problem, here is the nice article with cross browser support.

Snippet from article:

const binaryString = window.atob(fileResponseData);
const bytes = new Uint8Array(binaryString.length);
const mappedData = bytes.map((byte, i) => binaryString.charCodeAt(i));
const blob = new Blob([mappedData], { type: 'application/pdf' });
FileSaver.saveAs(blob, 'foo.pdf')

Post a Comment for "How To Convert Byte Array To Pdf And Download"