PDFsharp如何向文档添加复选框

时间:2017-10-19 00:02:42

标签: c# pdf pdfsharp

我一直在寻找将复选框添加到PDFsharp文档的最佳方法。

到目前为止,我只能使用Wingdings字体添加字符串"\u00fd"。只有在使用Acrobat Reader打开PDF文档时,它才有用。但是,如果Chrome或IE打开它,而不是复选框,它将显示一个不可读的字符。

PDFsharp的任何想法或更好的替代方案(免费或开源)?

我对PDF文档的要求非常简单,只需要一两份报告。

PDFsharp新手提供的以下链接嵌入字体。

勾选复选框:

XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode,
                                              PdfFontEmbedding.Always);

XFont prevCheckboxFont = new XFont("WingDings", 12, XFontStyle.Regular, options);

XRect prevCheckboxPos = new XRect(XUnit.FromInch(3.20), XUnit.FromInch(3.30),
                                  XUnit.FromInch(1.25), XUnit.FromInch(.10));
string prevCheckboxText = "\u00FE";
gfx.DrawString(prevCheckboxText, prevCheckboxFont, XBrushes.Black,
               prevCheckboxPos, XStringFormats.TopLeft);

1 个答案:

答案 0 :(得分:2)

我们使用Wingdings创建PDF格式的复选框,它们可以与Adobe Reader,Firefox和Chrome一起使用。

确保将字体嵌入PDF文件中。

对于旧版本1.32及更早版本,您必须指定一个标记以嵌入字体:

XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode,
                                              PdfFontEmbedding.Always);
XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);

对于当前版本(1.50及更高版本),始终嵌入字体并删除该选项。

另见:
http://www.pdfsharp.net/wiki/Unicode-sample.ashx
MigraDox C# Checkboxes - Wingdings Not Working