【发布时间】:2011-05-23 14:12:52
【问题描述】:
我不确定这是否可行,但我认为这值得一问。我已经弄清楚如何使用 pdfstamper 和 acrofields 方法设置表单字段的字体,但我真的希望能够在同一字段中设置文本不同部分的字体。以下是我当前设置表单字段字体的方式:
// Use iTextSharp PDF Reader, to get the fields and send to the
//Stamper to set the fields in the document
PdfReader pdfReader = new PdfReader(fileName);
// Initialize Stamper (ms is a MemoryStream object)
PdfStamper pdfStamper = new PdfStamper(pdfReader, ms);
// Get Reference to PDF Document Fields
AcroFields pdfFormFields = pdfStamper.AcroFields;
//create a bold font
iTextSharp.text.Font bold = FontFactory.GetFont(FontFactory.COURIER, 8f, iTextSharp.text.Font.BOLD);
//set the field to bold
pdfFormFields.SetFieldProperty(nameOfField, "textfont", bold.BaseFont, null);
//set the text of the form field
pdfFormFields.SetField(nameOfField, "This: Will Be Displayed In The Field");
// Set the flattening flag to false, so the document can continue to be edited
pdfStamper.FormFlattening = true;
// close the pdf stamper
pdfStamper.Close();
我希望能够在上面设置文本的地方将“此:”设置为粗体,并将“将在字段中显示”保持为非粗体。我不确定这实际上是否可行,但我认为值得一问,因为这对我目前的工作很有帮助。
提前致谢!
【问题讨论】:
标签: c# .net pdf fonts itextsharp