Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3918

create report in HINDI using PDFBox

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Information Provided
    • Affects Version/s: 2.0.7
    • Fix Version/s: None
    • Component/s: AcroForm
    • Labels:
      None
    • Environment:
      Windows 10

      Description

      Hello

      I am getting an error while generating a report i.e. "U+0938 is not available in this font's encoding: WinAnsiEncoding" and attaching the pdf which contain some acroform and their ids are Text1, Text2 and below i am giving my java code:

      import java.io.File;
      import java.util.List;

      import org.apache.pdfbox.pdmodel.PDDocument;
      import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
      import org.apache.pdfbox.pdmodel.interactive.form.PDField;

      public class PDFBoxLanguageTest {
      public static void main(String[] args) throws Exception {

      String formTemplate = "C:/Users/XXXX/Downloads/CPIS_test_language.pdf";
      PDDocument pdfDocument = PDDocument.load(new File(formTemplate));
      PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
      if (acroForm != null) {
      // Get field names
      List<PDField> fieldList = acroForm.getFields();
      for (PDField pdField : fieldList)

      { // Here i am passing a text in "Hindi" acroForm.getField(pdField.getFullyQualifiedName()).setValue("सुब्रत"); }

      }

      pdfDocument.save("C:/Users/XXXX/Downloads/CPIS_test_language1.pdf");
      pdfDocument.close();
      System.out.println("Done");
      }
      }

      Exception:
      Exception in thread "main" java.lang.IllegalArgumentException: U+0938 is not available in this font's encoding: WinAnsiEncoding
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.encode(PDTrueTypeFont.java:398)
      at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:323)
      at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:352)
      at org.apache.pdfbox.pdmodel.interactive.form.PlainTextFormatter.format(PlainTextFormatter.java:195)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:493)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:353)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:226)
      at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:263)
      at org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
      at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
      at com.sdrc.image.PDFBoxLanguageTest.main(PDFBoxLanguageTest.java:21)

        Attachments

        1. CPIS_test_language.pdf
          9 kB
          Subrata Kumar Pradhan

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              subrata1945 Subrata Kumar Pradhan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: