pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

RTL fonts (Hebrew) prints numbers **backwards** when entered with text

Open zeev-js opened this issue 3 years ago • 3 comments

RTL fonts (Hebrew) prints numbers backwards when entered with text.

Tested

  1. Several different fonts - Fail.
  2. Hebrew with no spaces - Fail
  3. Same font but in English - OK.
  4. 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

zeev-js avatar Feb 03 '22 02:02 zeev-js

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

llimos avatar Jun 08 '22 13:06 llimos

Are there any workarounds?

ahmafi avatar Aug 05 '23 12:08 ahmafi

Having the same issue, someone managed to find a solution?

molotbar avatar Sep 23 '23 15:09 molotbar