0

I have populated an acrofield with some Arabic data using PDFStamper. The text disappears when I flatten the form while it is working fine for English. Please guide.

     BaseFont unicode = null;
     unicode = BaseFont.createFont("D:/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
     form.setGenerateAppearances(true);
     form.addSubstitutionFont(unicode);
     form.setField("TextBox","اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب");
     stamper.setFormFlattening(true);
aanchal
  • 33
  • 1
  • 12

2 Answers2

0

It's probably an encoding problem when you save, compile or execute your code (which means your problem is not related to iText). This is the code I've tried:

PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
BaseFont unicode =
    BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
form.addSubstitutionFont(unicode);
form.setField("description", "\u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627 \u0628\u0627");
stamper.close();
reader.close();

This is what the result looks like:

enter image description here

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Hi Bruno, I tried your code and I am getting a blank pdf with a rectangle after flattening the form. Please help. – aanchal Jun 20 '14 at 10:09
  • I can only see the Arabic data when field is editable. Is there any issue with the font I am using? – aanchal Jun 20 '14 at 10:11
  • We are trying to pump the data from database( Arabic String not hardcoded in java code). It is not working in this scenario also. – aanchal Jun 20 '14 at 10:40
  • Which version of iText are you using? I've added the line that flattens the form to my example, and I get a good result. Maybe you're using a mighty old version of iText that doesn't support what you want. Also: if you're extracting the data from a database, make sure you get the bytes using the right encoding ("UTF-8"). – Bruno Lowagie Jun 20 '14 at 13:35
  • I am using iText 5.5 and the data is extracted in utf-8 encoding. I can see the data when i click on the textfield (without form flattening) but it disappears when i try to flatten the form. – aanchal Jun 20 '14 at 19:55
  • I'm sorry, I can't reproduce the problem. Please provide a SSCCE. If you don't know what a SSCCE is, see http://sscce.org – Bruno Lowagie Jun 21 '14 at 07:39
0

i had same problem. you must recreate your sourec pdf by adobe acrobat pro and set the font of your textbox to one of known fonts in your os like arial.

good luck.