【发布时间】:2018-10-18 13:05:57
【问题描述】:
我正在更新一个 C# 项目以使用 iText 7,并希望为表单字段中设置的值添加删除线效果。该代码最初使用旧版本的 iTextSharp,这使得创建删除线字体变得相当直观:
// older iTextSharp code
Font strikethruFont = new Font(normalBase, 11f, Font.STRIKETHRU);
但是我找不到任何示例或文档说明如何 1) 使用 iText 7 创建带有删除线的字体,如上面的 iText 7 并在表单字段中使用它或 2) 使用其他工具(PdfCanvas、Tables、Text 对象等)在设置其值之前向表单字段添加样式。
// somehow create a strikethrough font
PdfFont strikethruFont = ???
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
form.GetField("Some Field Name")
.SetValue("Some content to strike through", strikethruFont, 11f)
注意:我已经看到使用 Text 对象然后用负 y 偏移为它加下划线的示例(有效地将下划线拉到文本区域,模仿删除线)。不幸的是,Text 对象不能与 form.SetValue() 一起使用。
【问题讨论】:
标签: c# pdf itext pdf-generation itext7