简体   繁体   中英

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.

So far I'm only able to add a string "\ý" with the Wingdings font. It kinda works only if the PDF document is opened with the Acrobat Reader. But if Chrome or IE opens it, instead of a checkbox, it will show a unreadable character.

Any ideas or better alternative (free or open source) to PDFsharp?

My requirement for the PDF document is very easy and just one or two reports.

Followed links provided by PDFsharp Novice to embed the font.

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.

Make sure to embed the fonts in the PDF file.

With the old versions 1.32 and older you have to specify a flag to have the fonts embedded:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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