Copyright character in text

Nov 26, 2010 at 3:01 PM
Edited Nov 26, 2010 at 3:02 PM


If you want to include the copyright character in text that you "Drawstring", is there anything I need to keep in mind so that the symbol dont appear as a "?"

For example, where would I set the encoding that I use etc?

Thanks, Gert



PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
page.Orientation = PageOrientation.Portrait;

XGraphics gfx = XGraphics.FromPdfPage(page);

XRect xRect = new XRect(item.Position.X, item.Position.Y, item.Size.Width, item.Size.Height);
XFont font = BuildXFont(item.Font, item.FontSize);
XTextFormatter tf = new XTextFormatter(gfx);
tf.Alignment = allignment;
tf.DrawString(item.Text, font, XBrushes.Black, xRect);//, XStringFormats.TopLeft);



Nov 11, 2011 at 4:12 PM
Edited Nov 11, 2011 at 4:12 PM

OK, found the solution in the HelloWorld example :)

Construct the font correctly...

var pdfTextOptions = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
var font = new XFont(fontName, fontSize, style, pdfTextOptions);

Jan 26, 2012 at 7:57 PM
Edited Jan 26, 2012 at 8:04 PM

Hi there. I found some special character like copy right will display as "?" is because the font not have this character. you can input these word and print to PDF file. and you will see the copy right character use the font "Calibri". you can use this font to draw these character and set the font options encoding to Unicode.

some very useful skill: use word to input your content. print to pdf (use adobe pdf printer is better) and check the pdf file fonts.

This is my way to fix the blod style.



XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.None);
XFont titleFont = new XFont("Arial-BoldMT", 14);
XFont contentFont = new XFont("ArialMT", 14); XFont copyrightFont = new XFont("Calibri", 7, XFontStyle.Regular, options); var blackColor = new XSolidBrush(XColors.Black);

gfx.DrawString("hello world", titleFont, blackColor, 10, 10);
gfx.DrawString("hello world", contentFont, blackColor, 20, 10);
gfx.DrawString("©", copyrightFont, blackColor, 30, 10);