用 itextsharp 绘制复选框
Draw checked box with itextsharp
如何使用 iTextSharp 绘制复选框(带有 X)。
我不希望它是图像。更像符号
我试过了,但没用:
RadioCheckField fCell = new RadioCheckField(writer, new Rectangle(20,20), "NoDeletion", "Yes");
fCell.CheckType = RadioCheckField.TYPE_CROSS;
PdfFormField footerCheck = null;
footerCheck = fCell.CheckField;
writer.AddAnnotation(footerCheck);
谢谢,
谢谢,不过我找到了解决办法。这是:
var checkBox = new Phrase();
checkBox.Add(new Chunk(" ☒ ", new Font(BaseFont.CreateFont(PrintCommonConstants.UnicodeFontNormal, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 18)));
我假设您不需要交互式复选框。您只想使用复选框字符。您需要的第一件事是具有这种字符的字体。当我在 Windows 上工作时,我可以访问名为 WINGDING.TTF 的文件。这是一个包含各种符号的字体程序,其中包括一些复选框:
我创建了屏幕截图中显示的 PDF,如下所示:
public static final String DEST = "results/fonts/checkbox_character.pdf";
public static final String FONT = "c:/windows/fonts/WINGDING.TTF";
public static final String TEXT = "o x \u00fd \u00fe";
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.GetInstance(document, new FileOutputStream(dest));
document.Open();
BaseFont bf = BaseFont.CreateFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font f = new Font(bf, 12);
Paragraph p = new Paragraph(TEXT, f);
document.Add(p);
document.Close();
}
如您所见,空复选框对应字母o
,选中的复选框有三种变体。
如何使用 iTextSharp 绘制复选框(带有 X)。 我不希望它是图像。更像符号 我试过了,但没用:
RadioCheckField fCell = new RadioCheckField(writer, new Rectangle(20,20), "NoDeletion", "Yes");
fCell.CheckType = RadioCheckField.TYPE_CROSS;
PdfFormField footerCheck = null;
footerCheck = fCell.CheckField;
writer.AddAnnotation(footerCheck);
谢谢,
谢谢,不过我找到了解决办法。这是:
var checkBox = new Phrase();
checkBox.Add(new Chunk(" ☒ ", new Font(BaseFont.CreateFont(PrintCommonConstants.UnicodeFontNormal, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 18)));
我假设您不需要交互式复选框。您只想使用复选框字符。您需要的第一件事是具有这种字符的字体。当我在 Windows 上工作时,我可以访问名为 WINGDING.TTF 的文件。这是一个包含各种符号的字体程序,其中包括一些复选框:
我创建了屏幕截图中显示的 PDF,如下所示:
public static final String DEST = "results/fonts/checkbox_character.pdf";
public static final String FONT = "c:/windows/fonts/WINGDING.TTF";
public static final String TEXT = "o x \u00fd \u00fe";
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.GetInstance(document, new FileOutputStream(dest));
document.Open();
BaseFont bf = BaseFont.CreateFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font f = new Font(bf, 12);
Paragraph p = new Paragraph(TEXT, f);
document.Add(p);
document.Close();
}
如您所见,空复选框对应字母o
,选中的复选框有三种变体。