Arabic Data disappears on Form flattening in iText

折月煮酒 提交于 2019-12-01 12:48:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!