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 '&lt;';
                case '>': return '&gt;';
                case '&': return '&amp;';
                case '\'': return '&apos;';
                case '"': return '&quot;';
            }
        });
    }
    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:
    0_1719460761896_upload-b8bbc500-1947-4551-aec5-bbefbca7c3b8

    1. But it lost line break when I enabled unoconv and preview as PDF, and the reslut as below:
      0_1719460935785_upload-18f2a89b-7f4f-41fe-a7ca-271718db980f
    2. How to fix this issues?


  • Try this
    https://playground.jsreport.net/w/anon/0wMRK2eB

    Handlebars.SafeString(escapeXml(d).replace(/\n/g, '</w:t><w:br/></w:r><w:r><w:t>'));
    


  • @admin, thanks, good solution. works for me now.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.