I am currently working on a small website, on which it should be possible to upload a .pdf file. For the websites functionality, I need to read the text from the pdf into a variable, including the line breaks. So for example if the text in the pdf is:
Hello World
How are you today?
Then the text in the variable should be "Hello World\nHow are you today?".
I have tried several things, but none of these worked for me.
HTML:
<input type="file" id="file" accept=".pdf">
I have tried the following code in my app.js:
function readPdf(){
const file = document.getElementById('file').files[0];
const reader = new FileReader();
var output = "";
reader.addEventListener("load", function () {
output += reader.result;
}, false);
if (file) {
reader.readAsBinaryString(file);
}
return output;
}
But this is only giving me a hieroglyphic string.
Has anyone ever tried something like this and could tell me the way how it is done?
Thanks in advance