How to fix lost line breaks when using unoconv to convert DOCX to PDF?
-
How to fix lost line breaks when using unoconv to convert DOCX to PDF?
I used Docx template preview with Docx works well. but convert to PDF it lost line breaks.1.Word template like this:
{{preserveLineBreaks Description}}
2.preserveLineBreaks function like this:function escapeXml(unsafe) { return unsafe.replace(/[<>&'"]/g, function (c) { switch (c) { case '<': return '<'; case '>': return '>'; case '&': return '&'; case '\'': return '''; case '"': return '"'; } }); } function preserveLineBreaks(d) { if(d){ return new Handlebars.SafeString(escapeXml(d).replace(/\n/g, '<w:br/>')); } }
3.Preview as word it works well and result as below:
- But it lost line break when I enabled unoconv and preview as PDF, and the reslut as below:
- How to fix this issues?
- But it lost line break when I enabled unoconv and preview as PDF, and the reslut as below:
-
Try this
https://playground.jsreport.net/w/anon/0wMRK2eBHandlebars.SafeString(escapeXml(d).replace(/\n/g, '</w:t><w:br/></w:r><w:r><w:t>'));
-
@admin, thanks, good solution. works for me now.