код Java < /p>
package com.example.demo2.demos.test;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.*;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
public class pdfWrite { public static void fillFormFields(InputStream inputStream, String outputPdfPath, Map fieldValues) {
// 获取pdf中的表单域
String pdfPath = new String();
// 填写表单域并保存
outputPdfPath = new String();
fieldValues = new HashMap();
fieldValues.put("school", "XX大学");
fieldValues.put("student", "张三");
fieldValues.put("text1", "12111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113");
try {
inputStream = new FileInputStream(pdfPath);
PdfReader reader = new PdfReader(inputStream);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdfPath));
AcroFields form = stamper.getAcroFields();
// 嵌入字体
BaseFont base = BaseFont.createFont ("simfang.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
for (Map.Entry entry : fieldValues.entrySet()) {
String fieldName = entry.getKey();
String fieldValue = entry.getValue();
form.setFieldProperty(fieldName, "textfont", base, null);
form.setField(fieldName, fieldValue);
}
stamper.setFormFlattening(true);
stamper.close();
reader.close();
} catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
}
< /code>
pom.xml
com.lowagie
itext
2.1.7
< /code>

I have a PDF file containing form fields, one of which is a multi-line text field. When filling this field using Java code, I need to adjust the line spacing between rows. Specifically, I'm using iText (version 2.1.7) and have already tried setting the leading property, but the spacing doesn't appear to change as expected.I tried converting the field to a rich text box and writing style attributes, but it didn't work.
Подробнее здесь: https://stackoverflow.com/questions/796 ... especially