I am trying to fill a form field in an existing pdf file with Arabic text from a java servlet using iText.

English works great but for Arabic the field shows garbage.

I tried to play with the text field properties using adobe acrobat Middle Eastern edition. I changed the font to Arial and the subset into Arabic.

Filling fields with Arabic from inside adobe acrobat works but from the servlet it still shows garbage until I click on the field for edit then it shows fine.

If I click away from the field it converts into garbage again. If form flattening is set to true (which I want to do) it shows unmodified garbage.

 Here is the code from the servlet doGet method:

 

 

      OutputStream out = response.getOutputStream();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

         try {

             PdfReader reader = new PdfReader("c:\\visa2.pdf");      

             PdfStamper stamp = new PdfStamper(reader, baos );

 

      

             AcroFields form = stamp.getAcroFields();

           

             form.setField("Text1", "أيمن" );  //Arabic text in the second parameter

 

            //stamp.setFormFlattening(true);         //commented out to show the weird behavior with edit if not commented shows unmodified garbage

             stamp.close();

            response.setContentLength(baos.size());

             baos.writeTo( out );

             baos.flush();

             baos.close();

             out.flush();

             out.close();

}

      catch(Exception e){System.out.println(e.getMessage());}                      

Reply via email to