我的代码将文本设置到字段中没有问题,但是当我尝试更改字体时它返回 false。我尝试了其他一些字段属性,例如具有相同结果的文本大小。我究竟做错了什么?
public string Build()
{
Font font = FontFactory.GetFont(FontFactory.COURIER, 8f, Font.BOLD);
foreach (var i in this.pdfFields)
{
bool worked = this.acroFields.SetFieldProperty(i.Name, "textfont", font.BaseFont, null);
worked = this.acroFields.SetField(i.Name, i.Value);
}//foreach
this.pdfStamper.FormFlattening = false;
this.pdfStamper.Close();
return this.newFile;
}//Build
附录
private string templateFile;
private string newFile;
private PdfReader pdfReader;
private PdfStamper pdfStamper;
private AcroFields acroFields;
private List<PDFField> pdfFields;
public PDFer(string templateFile, string newFile)
{
this.templateFile = templateFile;
this.newFile = newFile;
this.pdfReader = new PdfReader(this.templateFile);
this.pdfStamper = new PdfStamper(pdfReader, new FileStream(this.newFile, FileMode.Create));
this.acroFields = pdfStamper.AcroFields;
this.pdfFields = new List<PDFField>();
}//PDFer
public void AddTextField(string name, string value)
{
this.pdfFields.Add(new PDFTextField(name, value));
}//AddTextField
public void AddCheckBox(string name, bool isChecked)
{
this.pdfFields.Add(new PDFCheckBox(name, isChecked));
}//AddCheckBox
public float getWidth(string s)
{
Chunk c = new Chunk(s);
return c.GetWidthPoint();
}//getWidth