Javascript 将pdf(编码:UniJIS-UCS2-H)转换为base64

Javascript 将pdf(编码:UniJIS-UCS2-H)转换为base64,javascript,character-encoding,xmlhttprequest,base64,Javascript,Character Encoding,Xmlhttprequest,Base64,我有一个编码为UniJIS-UCS2-H的pdf。我想用javascript将其转换为base 64。 我这样写代码。它可以将其转换为pdf格式,但内容不可见。 我的代码如下所示 function getBinary(file){ var xhr = new XMLHttpRequest(); xhr.open("GET", file, false); xhr.overrideMimeType("application/pdf; charset=UniJIS-UCS

我有一个编码为UniJIS-UCS2-H的pdf。我想用javascript将其转换为base 64。 我这样写代码。它可以将其转换为pdf格式,但内容不可见。 我的代码如下所示

function getBinary(file){
    var xhr = new XMLHttpRequest();  
    xhr.open("GET", file, false);  
   xhr.overrideMimeType("application/pdf; charset=UniJIS-UCS2-H");  
    xhr.send(null);
    return xhr.responseText;
}

function base64encode(binary) {
    return btoa(unescape(encodeURIComponent(binary)));
}

var binary = getBinary('http://localhost/first.pdf');
var base64encoded = base64encode(binary);
data = "data:application/pdf;base64,"+base64encoded;
数据仅包含普通pdf。我如何解决它