jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Missing characters when rendering an arabic text

Open abdelaziz321 opened this issue 7 years ago • 6 comments

Hey,

As the title says, I have Cairo-Regular-normal.js file contains:

export const Cairo = 'AAEAAAARAQAABA.....';

And Card.js file contians:

<script>
import * as jsPDF from 'jspdf';
import html2canvas from 'html2canvas';
import { Cairo } from '@/assets/fonts/Cairo-Regular-normal.js';

export default {
  methods: {
    download(student) {
      const card = document.querySelector('#card-to-be-printed');
      html2canvas(card)
        .then((canvas) => {
          let pdfElement = document.getElementById('pdf');
          pdfElement.appendChild(canvas);

          let doc = new jsPDF('portrait', 'mm', 'a4');

          // set image
          doc.addImage(canvas.toDataURL('image/png'), 'PNG', 5, 5);

          // Set Cairo Font
          doc.addFileToVFS('Cairo-Regular.ttf', Cairo);

          doc.addFont('Cairo-Regular.ttf', 'Cairo-Regular', 'normal');
          doc.setFont('Cairo-Regular');
          doc.setFontSize(15);

          // set student name
          const studentName = doc.processArabic(student.name);
          console.log(studentName);
          
          doc.text(studentName, 52, 27.5, { align: 'center' });

          doc.save(`student_${student.id}.pdf`);
          pdfElement.innerHTML = '';
      });

      this.$emit('success', student);
      this.dialog = false;
    }
  }
};
</script>

- The console.log(studentName); print this line:

Screenshot from 2019-11-10 20-59-37

- But the generated pdf contains the text without some characters:

Screenshot from 2019-11-10 21-07-02

These Characters are missing: ــــ اــــ أـــ اــــم

abdelaziz321 avatar Nov 10 '19 19:11 abdelaziz321

Changing the font works. You could try Amiri.

kamranmuazzam avatar Dec 02 '19 09:12 kamranmuazzam

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

github-actions[bot] avatar Jul 06 '20 01:07 github-actions[bot]

i'm having the same problem

slimani-dev avatar Oct 30 '21 19:10 slimani-dev

@moh-slimani this comment may help you: https://github.com/niklasvh/html2canvas/issues/686#issuecomment-552733490

abdelaziz321 avatar Oct 30 '21 19:10 abdelaziz321

@moh-slimani this comment may help you: niklasvh/html2canvas#686 (comment)

i fixed the problem with changing the font it would have been great if i could use the Cairo font which seem to be the only font that has this issue so far thanks anyway

slimani-dev avatar Nov 10 '21 22:11 slimani-dev

Almarai font has the same issue

fahdarafat avatar Aug 29 '23 15:08 fahdarafat