问题
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);
回答1:
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:
回答2:
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.
来源:https://stackoverflow.com/questions/24305574/arabic-data-disappears-on-form-flattening-in-itext