html2pdf.js
html2pdf.js copied to clipboard
why with arabic text html2pdf remove last space before last word of the sentance ?
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
any help please.
@eKoopmans please see attachment
my solutions is :
str_replace(' ',' ', $name)
@hakimezzahraoui many thanks for you , but there is a simple problem with sentence if it contains brackets. اللغة العربية (نحو وصرف) will become: )اللغة العربية)نحو وصرف
@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 , 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();
@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
The solution is Change font family for Example .parent-container{ font-family: 'Courier New', Courier, monospace; }
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") })
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
After I fall into the problem again ، I puted every word between span ، this fix my problem
my solutions is :
str_replace(' ',' ', $name)
can you explain with example or something ? i didnt get this
@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