简体   繁体   中英

How can I use a monospace font with PDFsharp?

I am trying to use the "Courier" font with PDFsharp to use its monospace feature, but when I use this font using the library the written text is not monospaced or fixed-width.

This is the code:

// Obtain an XGraphics object to render to
XGraphics gfx = XGraphics.FromPdfPage(page);

// Create a font
double fontHeight = 8;
XFont font = new XFont("Courier", fontHeight, XFontStyle.Regular);
XTextFormatter tf = new XTextFormatter(gfx);

String text = "Hello\r\nMy name is John\r\nMy name, is Peter.";
XRect rect = new XRect(0, 0, 200, 200);
gfx.DrawRectangle(XBrushes.SeaShell, rect);
tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

The letter "i" and the character "." break the width.

使用计算机上安装的字体,例如“ Courier New”而不是“ Courier”。

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