简体   繁体   English

PDFsharp如何向文档添加复选框

[英]PDFsharp how to add checkboxes to document

I've been looking around on what's the best way to add a checkbox to a PDFsharp document. 我一直在寻找向PDFsharp文档添加复选框的最佳方法是什么。

So far I'm only able to add a string "\ý" with the Wingdings font. 到目前为止,我只能添加带有Wingdings字体的字符串"\ý" It kinda works only if the PDF document is opened with the Acrobat Reader. 仅当使用Acrobat Reader打开PDF文档时,它才起作用。 But if Chrome or IE opens it, instead of a checkbox, it will show a unreadable character. 但是,如果Chrome或IE打开它,而不是一个复选框,它将显示一个不可读的字符。

Any ideas or better alternative (free or open source) to PDFsharp? 对PDFsharp有任何想法或更好的选择(免费或开源)?

My requirement for the PDF document is very easy and just one or two reports. 我对PDF文档的要求非常简单,只有一两个报告。

Followed links provided by PDFsharp Novice to embed the font. 单击PDFsharp新手提供的链接以嵌入字体。

Draw the checkbox: 绘制复选框:

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);

We use Wingdings to create checkboxes in PDF and they work with Adobe Reader, Firefox, and Chrome. 我们使用Wingdings在PDF中创建复选框,它们可与Adobe Reader,Firefox和Chrome一起使用。

Make sure to embed the fonts in the PDF file. 确保将字体嵌入PDF文件中。

With the old versions 1.32 and older you have to specify a flag to have the fonts embedded: 对于旧版本1.32和更高版本,您必须指定一个标记来嵌入字体:

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

With current versions (1.50 and higher) fonts are always embedded and the option was removed. 在当前版本(1.50和更高版本)中,始终会嵌入字体并删除该选项。

See also: 也可以看看:
http://www.pdfsharp.net/wiki/Unicode-sample.ashx http://www.pdfsharp.net/wiki/Unicode-sample.ashx
MigraDox C# Checkboxes - Wingdings Not Working MigraDox C#复选框-机翼无法正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM