My question is almost the same to the following post Certain PDF files won't open but in my case is simpler. I can't load PDF files larger than 2MB, with smaller files works fine.
When I use readAsDataURL method, the reader.result would seem to be sliced. I made comparition between base64 generated by the example below (my case) and online tool that works fine, to my bse64 missing the last part (a big one).
If someone knows something about this behaviour and can give me a hint i will be grateful.
My code below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="height: 100%;">
<button onclick="getFile(event)">Get File</button>
<input id="pdfInputFile" type="file" accept="application/pdf" style="display:none" onchange="loadPDF(this);" />
<object id="pdfViewer" type="application/pdf" style="height:100%; width:100%;border:solid 1px" >
</object>
</body>
<script>
function getFile(e) {
e.preventDefault();
document.getElementById("pdfInputFile").click();
}
function loadPDF(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById("pdfViewer").setAttribute('data', reader.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
</html>