pdf-lib
pdf-lib copied to clipboard
RTL fonts (Hebrew) prints numbers **backwards** when entered with text
RTL fonts (Hebrew) prints numbers backwards when entered with text.
Tested
- Several different fonts - Fail.
- Hebrew with no spaces - Fail
- Same font but in English - OK.
- Hebrew but only digits(no text e.g. "12345") - OK.
I briefly went over the code and couldn't find the reason, tried exploring the fontkit as well but no success.
How can we reproduce the issue?
Fonts used: Open Sans
import { PDFForm } from 'pdf-lib'
import fontkit from '@pdf-lib/fontkit';
import fs from 'fs'
PDFDocument.load(formPdfBytes).then(async pdfDoc =>{
pdfDoc.registerFontkit(fontkit);
const font = await pdfDoc.embedFont(fs.readFileSync('./font.ttf'), { subset: true });
const form= pdfDoc.getForm();
const value = "כתובת 12345" //"Address 12345"
form.getTextField(field.name).setText(value);
form.getTextField(field.name).getText() //OK "כתובת 12345"
form.updateFieldAppearances(font); //Passes but prints "כתובת 54321"
const bytes = await pdfDoc.save();
fs.writeFileSync('./save.pdf', bytes) ;
});
Version
latest
What environment are you running pdf-lib in?
Node
Having the same issue with Rubik Medium font. Probably going to work around it by detecting in code when there are Hebrew letters and numbers, and flipping the numbers
Are there any workarounds?
Having the same issue, someone managed to find a solution?