我制作了一个带有多行文本框的 pdf 模板,并且必须使用 PDFStamper 在 Acrofields 中设置一些阿拉伯语数据。文本的运行方向对于第一行是正确的,但在发生文本换行时会发生变化。
请指导。
package test;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class TextFields{
public static final String RESULT1 = "D:/template.pdf";
public static final String RESULT2 = "D:/pdf/result.pdf";
protected int tf;
public TextFields(int tf) {
this.tf = tf;
}
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
FontFactory.registerDirectories();
BaseFont unicode = null;
unicode = BaseFont.createFont("D:/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
stamper.getAcroFields().addSubstitutionFont(unicode);
form.setField("TextBox","اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب اب");
stamper.close();
reader.close();
}
public static void main(String[] args) throws DocumentException, IOException {
TextFields example = new TextFields(0);
example.manipulatePdf(RESULT1, RESULT2);
}
}