I have this PDF file which i need to convert into an array of byte value numbers.
I have previously converted it to base64 but the conversion of PDF to base64 took forever for a 2MB PDF. Is there another way to convert PDF to base64 faster OR convert that PDF file into array of bytes(to see if its faster than converting to base64)?
i am using filereader to read the file into dataURL previously. Below is the code i am using to convert to base64.
getFileContentAsBase64(path, callback) {
window.resolveLocalFileSystemURL(path, gotFile, fail);
function fail(e) {
alert('Cannot found requested file');
}
function gotFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function (e) {
var content = this.result;
callback(content);
}
reader.readAsDataURL(file);
});
}
}
EDIT:
getFileContentAsBase64(path, callback) {
window.resolveLocalFileSystemURL(path, gotFile, fail);
function fail(e) {
alert('Cannot found requested file');
}
function gotFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function (e) {
var content = this.result;
var array = new Uint8Array(content);
var binaryString = String.fromCharCode.apply(null, array);
callback(content);
}
reader.readAsArrayBuffer(file);
});
}
}