question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing characters when rendering an arabic text

See original GitHub issue

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: ــــ اــــ أـــ اــــم

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
moh-slimanicommented, Nov 10, 2021

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing characters when rendering an arabic text · Issue #2613
Hey, As the title says, I have Cairo-Regular-normal.js file contains: export const Cairo = 'AAEAAAARAQAABA.....'; And Card.js file contians:
Read more >
iText & Arabic pdfs ocasionally missing characters
In our case - The document was authored in MS Word in Arabic. When you select a single character and Alt+x, in MS...
Read more >
Arabic characters do not display correctly when saving and ...
When I save a text file with arabic letters from Notepad, they do not show correctly after reopening. Instead it shows ?
Read more >
Fixing Arabic fonts typing problem in Adobe illustrator|Super fast
Even with a font that supports Arabic text (e.g. Arial), the text is back to front (left to right, not right to left)...
Read more >
If non-Latin fonts don't appear correctly on Mac - Apple Support
On your Mac, change the order of your preferred languages to have text appear correctly in Chinese, Japanese, Korean, Arabic, Persian, and more....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found