Search code examples
c#pdfitextitext7

IText 7 with C# acroforms flattening problem when working with RTL


I am using IText 7 with C# to fill "acroForms" programmatically. I found how to do it when dealing with RTL languages.

The problem occurs when I need to disable (flatten) an input field , the value disappears.

When I use LTR (English) the values are disabled - flattened and everything works well.

The code:

PdfDocument pdf = new PdfDocument(new PdfReader(@"C:\test\test.pdf"), new PdfWriter(@"C:\test\test2.pdf"));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
form.SetNeedAppearances(true);
IDictionary<String, PdfFormField> fields = form.GetFormFields();
PdfFormField toSet;
fields.TryGetValue("CM@SHEM_PRATI@1", out toSet);
toSet.SetValue("גגג");
form.PartialFormFlattening("CM@SHEM_PRATI@1");
form.FlattenFields();
pdf.Close();

Do I miss a configuration for flattening RTL inserted fields? Is there another way to disable input fields with C# Itext 7?


Solution

  • The problem was solved. I added the itext7.pdfcalligraph add-on. Then added an rtl font to the code above:

    PdfFont heb = PdfFontFactory.CreateFont(@"/path/to/font.ttf", "Identity-H", true);
    toSet.SetFont(heb);
    

    The input field flattened and the value still could be seen.