How to read docx with line breaks in website js?

Viewed 158

I am currently working on a web app for which I need to read text from a .docx-file in the front-end, using JavaScript. For the later usage of the text it's important to also read linebreaks in the text. Currently I am working with docxtemplater's getFullText()-method, which is fine to read the text, but it does not give me the line breaks.

My current code lokes as follows:

function openDocx(event) {
    var input = event.target;
    var reader = new FileReader();
    reader.onload = function () {
        var zip = new JSZip(reader.result);
        var doc = new window.docxtemplater().loadZip(zip);
        var text = doc.getFullText();
        console.log(text)
    };
    reader.readAsBinaryString(input.files[0]);
};

So for the text in a .docx, let's say

Hello World
How are you?

It would give me "Hello WorldHow are you?", but I would want "Hello World\nHow are you?". Has anybody else had the same problem and found a solution or does anybody have an idea how to get the line breaks? If necessarry, I am also willing to go away from docxtemplater and use another library.

Thanks in advance

Robert

0 Answers
Related