1
votes

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 "\u00fd" 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);
1
If you need help to fix your code then please show some code.I liked the old Stack Overflow
So it seems you are not using the latest version (1.50), but a very old version (1.32 or earlier). Does it work now? If not, would you provide a PDF? The code snippet does not show the code that draws the checkbox.I liked the old Stack Overflow
@PDFsharpNovice I added the part that draws the checkbox. It is working now. Chrome and IE are showing the correct checkbox on my laptop but I need to run some more tests and run it on the server. And I have the latest stable version 1.32.3057. Does this code looks correct or is there an updated way to do this?causita
@causita - Were you able to insert checkboxes?NcDreamy
@ncdreamy yes, I used the answer belowcausita

1 Answers

2
votes

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