Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make hebrew works #3807

Open
p84torres opened this issue Dec 30, 2024 · 1 comment
Open

How to make hebrew works #3807

p84torres opened this issue Dec 30, 2024 · 1 comment

Comments

@p84torres
Copy link

Hello,
I'm using the last version 2.5.1 but I can't render a PDF with Hebrew, even if I Set the language, for example:

`const { jsPDF } = window.jspdf;

const doc = new jsPDF();
doc.setFont('Arial');
doc.text(10, 10, 'תן אישור כשירות מחדש ע"י רשות הרישוי ינתן עם החזרת טופס הודעה בדבר תקינות הרכב החתום ע"י מכון הרישוי.');
doc.setLanguage("he")
doc.save('MyTest.pdf');
`

What I see in the PDF:

image

Thanks in advance

@bhargav-tibadiya
Copy link

Hey @p84torres,

I have been using jsPDF for quite some time and have worked with various languages. The default fonts in jsPDF do not support Hebrew or other right-to-left (RTL) languages out of the box. Additionally, setting the language in jsPDF (doc.setLanguage("he")) does not automatically enable proper rendering for non-Latin scripts like Hebrew.


Here’s What You Can Do to Fix It

  1. Download a Hebrew-Supporting Font
  2. Convert the Font to Base64
  3. Embed the Font in jsPDF using addFileToVFS

Sample Code

import { jsPDF } from "jspdf";
// This is the Base64 font.
import hebrewFont from "./font.js"; 

const doc = new jsPDF();
doc.addFileToVFS("hebrew.ttf", hebrewFont);
doc.addFont("hebrew.ttf", "hebrew", "normal");
doc.setFont("hebrew"); // Use the added Hebrew font

const hebrewText = `"תן אישור כשירות מחדש ע"י רשות הרישוי ינתן עם החזרת טופס הודעה בדבר תקינות הרכב החתום ע"י מכון הרישוי."`;

doc.text(hebrewText, 10, 10, { align: "right" }); // Use align "right" for RTL
doc.save("MyTest.pdf");

References

If you need more references, check out my repository: - Recibill
I’ve implemented it here: - Recibill PDF Utils


If you still face issues, then you can go to my profile and you will find my contact details there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants