0

I have a word file, which I need to read, but using doc.getFullText() newlines are not read.

How can I do?

<script src="https://cdnjs.cloudflare.com/ajax/libs/docxtemplater/3.8.0/docxtemplater.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.6.1/jszip.js"></script>
const reader = new FileReader();
reader.onload = async (e) => {
 const text = e.target.result;
 const zip = new JSZip(text);
 const doc = new window.docxtemplater().loadZip(zip).setOptions({ linebreaks:true });
 const t = doc.getFullText();
 console.log(t)
};
reader.readAsBinaryString(files[0]);

Docx:

1
00:00:01.392 --> 00:00:03,734
[Speciale Natale uomo che corre]

2
00:00:05,611 --> 00:00:08.098
<i>[L'incubo di Natale]
Sottotitoli di DramaFever</i>

3
00:00:10,586 --> 00:00:14,909
[Un giorno piovoso di dicembre...]

4
00:00:17,251 --> 00:00:18,776
Cosa stai facendo qui?

5
00:00:20,035 --> 00:00:21,529
Cosa stai facendo davanti
di casa mia?
macropod
  • 12,757
  • 2
  • 9
  • 21
Paul
  • 3,644
  • 9
  • 47
  • 113

1 Answers1

0

Try this code :

const doc = new Docxtemplater(zip, {linebreaks: true});

if you want to render on html replace \n to <br>

Or

You can try with this library any-text

Nay Lin Aung
  • 164
  • 9
  • Should I get the text using `doc.getFullText()`? If this is not the case, the text is given without wrapping. – Paul Feb 21 '22 at 20:09
  • I found this issues [link](https://github.com/open-xml-templating/docxtemplater/issues/485) – Nay Lin Aung Feb 21 '22 at 20:38