0

I'm getting my pdf file through URL then save the base64 on a variable, if the file i'm getting is an IMAGE, it works well but if it's PDF, it doesn't work. The data is empty.

function toDataURL(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.onload = function() {
        var reader = new FileReader();
        reader.onloadend = function() {
            console.log(reader.result)
            callback(reader.result);
        };
        reader.readAsDataURL(xhr.response);
    };
    xhr.open('GET', url);
    xhr.responseType = 'blob';
    xhr.send();
}
Al Bassam
  • 9
  • 1
  • 5
  • Possible duplicate of [FileReader losing data when reading PDF](https://stackoverflow.com/questions/44664814/filereader-losing-data-when-reading-pdf) – Durga Feb 15 '19 at 09:09
  • Possible, but I'm getting a data not posting. – Al Bassam Feb 15 '19 at 09:21
  • I encountered something similar a while ago, and I used a npm module something like **pdf2json** or something like that so I can parse the pdf to json and read it. Hope that helps. – squeekyDave Feb 15 '19 at 11:36

0 Answers0