html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

why with arabic text html2pdf remove last space before last word of the sentance ?

Open mshqlaih opened this issue 3 years ago • 14 comments

hi every body Why When i use html2pdf with arabic text i saw that the last space before the last word of the sentance is removed.

for example see the following sentance : ماهر جابر شقليه when i use html2pdf with The previous sentence i get this sentance : ماهر جابرشقليه

Thanks Maher

mshqlaih avatar Apr 09 '21 10:04 mshqlaih

any help please.

mshqlaih avatar Apr 16 '21 08:04 mshqlaih

@eKoopmans please see attachment Screenshot (46)_LI

mshqlaih avatar Apr 16 '21 08:04 mshqlaih

my solutions is : str_replace(' ',' ', $name)

hakim2c avatar May 06 '21 22:05 hakim2c

@hakimezzahraoui many thanks for you , but there is a simple problem with sentence if it contains brackets. اللغة العربية (نحو وصرف) will become: )اللغة العربية)نحو وصرف

mshqlaih avatar May 07 '21 07:05 mshqlaih

@mshqlaih When I'm using the Arabic text, texts are overlapping. I found your screenshot doesn't look those overlapping issues. Do you add any special font/conditions to tackle it?

vishnudas707 avatar May 17 '21 11:05 vishnudas707

@vishnudas707 , no i did not add any special font. just i used the following code:

var element = document.getElementById('pdfTable');

// Generate the PDF.
html2pdf().from(element).set({
  margin: 0.05,
  image: { type: "jpeg", quality: 0.80 },      
  filename: apex.item('P51_REPORT_NAME').getValue(),
  html2canvas: { scale: 1.2,dpi: 300},
  pagebreak:'css',      
  jsPDF: {orientation:apex.item('P51_ORIENTATION').getValue(), unit: 'pt', format: 'A4', compressPDF: true}
}).save();

mshqlaih avatar May 17 '21 13:05 mshqlaih

@vishnudas707 , no i did not add any special font. just i used the following code:

var element = document.getElementById('pdfTable');

// Generate the PDF.
html2pdf().from(element).set({
  margin: 0.05,
  image: { type: "jpeg", quality: 0.80 },      
  filename: apex.item('P51_REPORT_NAME').getValue(),
  html2canvas: { scale: 1.2,dpi: 300},
  pagebreak:'css',      
  jsPDF: {orientation:apex.item('P51_ORIENTATION').getValue(), unit: 'pt', format: 'A4', compressPDF: true}
}).save();

@mshqlaih Thanks word-wrap:normal property saved me. I think for your bracket you may need to 'dir:rtl' property. I hope this below link may help you https://github.com/eKoopmans/html2pdf.js/issues/242

vishnudas707 avatar May 17 '21 17:05 vishnudas707

The solution is Change font family for Example .parent-container{ font-family: 'Courier New', Courier, monospace; }

aymansyedalahl avatar Jun 03 '21 23:06 aymansyedalahl

This is the solution for spaces - I'm using in Hebrew text it's like an Arabic issue, the same problem const texts=document.querySelectorAll('.text') texts.forEach(text=>{ console.log(text); text.innerHTML = text.innerText.replace(/\s/g,"\u00a0") })

mcorcias avatar Jun 09 '21 09:06 mcorcias

This is the solution for spaces - I'm using in Hebrew text it's like an Arabic issue, the same problem const texts=document.querySelectorAll('.text') texts.forEach(text=>{ console.log(text); text.innerHTML = text.innerText.replace(/\s/g,"\u00a0") })

Worked well in the Persian language. Thanks

ghonchesefidi avatar Jun 30 '21 07:06 ghonchesefidi

After I fall into the problem again ، I puted every word between span ، this fix my problem

aymansyedalahl avatar Aug 23 '21 21:08 aymansyedalahl

my solutions is : str_replace(' ',' ', $name)

can you explain with example or something ? i didnt get this

lMicklel avatar Nov 13 '21 19:11 lMicklel

@mshqlaih I solved my problem by load every latest library like that


<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.2.8/es6-promise.min.js" ></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js" ></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.min.js" ></script>

<script> 
function smartPrint(html, filename = '', orientation = 'portrait') {
    if (filename) {
        filename = filename + ".pdf"
    } else {
        filename = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + ".pdf";
    }
    var opt = {
        margin: 1,
        filename: filename,
        image: { type: 'jpeg', quality: 0.98 },
        html2canvas: { scale: 2 },
        jsPDF: { unit: 'in', format: 'letter', orientation: orientation }
    };
    html2pdf().set(opt).from(html).save();

}
//try this
var html='ماهر جابر شقليه';
smartPrint(html);
</script>

the problem with html2pdf.bundle.min.js version

Arafat-Thabet avatar Apr 29 '22 00:04 Arafat-Thabet