从 .NET 应用程序打印时符号字体被光栅化
Symbol font is rasterized when printing from .NET application
我正在通过打印到设置为打印到文件的 Postscript 打印机来从 C# 创建 Postscript 文件。我正在使用 .NET PrintDocument class 和 Graphics.DrawString 来呈现文本。
如果我使用符号或象形文字字体(例如 Symbol 或 WingDings),则文本在 Postscript 文件中会被光栅化。如果我使用例如Arial,则文本未被栅格化。我的目标是从我的应用程序生成一个 Postscript 文件,其中使用符号字体的文本未被栅格化。
如果我使用符号字体打印相同的文本,例如notepad 文本未光栅化,因此乍一看似乎不是打印机驱动程序的限制。
我在做什么wrong/different导致光栅化?
- 打印机的字体替换table设置为不替换字体。
- 符号字体在我试过的打印机上可用。
- 选择另一个 Postscript 打印机驱动程序没有区别。
- 使用 TextRenderer.DrawText 产生相同的结果。
- 使用来自其他应用程序(记事本、Word 等)的 Symbol 字体进行打印 不会 产生光栅化输出。
#region Usings
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
#endregion
public class PrintingExample
{
private string _fontName;
private string _printerName;
private string _textToPrint;
//private bool endPrintFired = false;
// private bool keepGoing = true;
private Font printFont;
public PrintingExample(string fontName, string printerName, string textToPrint)
{
_fontName = fontName;
_printerName = printerName;
_textToPrint = textToPrint;
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
const float fontSize = 14.0f;
var fFamily = new FontFamily(_fontName);
printFont = new Font(fFamily, fontSize, FontStyle.Regular, GraphicsUnit.Point);
var leftMargin = ev.MarginBounds.Left;
var topMargin = ev.MarginBounds.Top;
ev.Graphics.DrawString(_textToPrint, printFont, Brushes.Black, new Point(leftMargin, topMargin), new StringFormat());
// Only printing one page
ev.HasMorePages = false;
}
// Print the file.
public void Printing()
{
try
{
var outputFile = string.Empty;
try
{
outputFile = Path.Combine(@"c:\temp\print\", Path.GetRandomFileName() + ".ps");
var pd = new PrintDocument {PrinterSettings = {
PrinterName = _printerName,
PrintToFile = true,
PrintFileName = outputFile}
};
pd.PrintPage += pd_PrintPage;
PrintController pc = new StandardPrintController();
PrintController printController = new PrintControllerWithStatusDialog(pc);
pd.PrintController = printController;
// Print the document.
pd.Print();
}
finally
{
// For debugging, loads in default associated application
if (File.Exists(outputFile))
Process.Start(outputFile);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// This is the main entry point for the application.
public static void Main(string[] args)
{
const string fontName = "Symbol";
const string printerName = "<Choose an installed Postscript printer here>";
const string textToPrint = "1234567890\r\nabcdefghijklmnopqrstuvwxyz";
var p = new PrintingExample(fontName, printerName, textToPrint);
p.Printing();
}
}
这原来是 Windows 2012R2、10、Server 2016 和 Server 2019 中的一个错误(服务器 2008R2 未受影响,这导致我们打开了一个 MS 案例)。只有一些字体受到影响。 Windows 10、Server 2016 和 Server 2019
的 2021 年 3 月 OS 更新解决了这个问题
我正在通过打印到设置为打印到文件的 Postscript 打印机来从 C# 创建 Postscript 文件。我正在使用 .NET PrintDocument class 和 Graphics.DrawString 来呈现文本。
如果我使用符号或象形文字字体(例如 Symbol 或 WingDings),则文本在 Postscript 文件中会被光栅化。如果我使用例如Arial,则文本未被栅格化。我的目标是从我的应用程序生成一个 Postscript 文件,其中使用符号字体的文本未被栅格化。
如果我使用符号字体打印相同的文本,例如notepad 文本未光栅化,因此乍一看似乎不是打印机驱动程序的限制。
我在做什么wrong/different导致光栅化?
- 打印机的字体替换table设置为不替换字体。
- 符号字体在我试过的打印机上可用。
- 选择另一个 Postscript 打印机驱动程序没有区别。
- 使用 TextRenderer.DrawText 产生相同的结果。
- 使用来自其他应用程序(记事本、Word 等)的 Symbol 字体进行打印 不会 产生光栅化输出。
#region Usings
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
#endregion
public class PrintingExample
{
private string _fontName;
private string _printerName;
private string _textToPrint;
//private bool endPrintFired = false;
// private bool keepGoing = true;
private Font printFont;
public PrintingExample(string fontName, string printerName, string textToPrint)
{
_fontName = fontName;
_printerName = printerName;
_textToPrint = textToPrint;
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
const float fontSize = 14.0f;
var fFamily = new FontFamily(_fontName);
printFont = new Font(fFamily, fontSize, FontStyle.Regular, GraphicsUnit.Point);
var leftMargin = ev.MarginBounds.Left;
var topMargin = ev.MarginBounds.Top;
ev.Graphics.DrawString(_textToPrint, printFont, Brushes.Black, new Point(leftMargin, topMargin), new StringFormat());
// Only printing one page
ev.HasMorePages = false;
}
// Print the file.
public void Printing()
{
try
{
var outputFile = string.Empty;
try
{
outputFile = Path.Combine(@"c:\temp\print\", Path.GetRandomFileName() + ".ps");
var pd = new PrintDocument {PrinterSettings = {
PrinterName = _printerName,
PrintToFile = true,
PrintFileName = outputFile}
};
pd.PrintPage += pd_PrintPage;
PrintController pc = new StandardPrintController();
PrintController printController = new PrintControllerWithStatusDialog(pc);
pd.PrintController = printController;
// Print the document.
pd.Print();
}
finally
{
// For debugging, loads in default associated application
if (File.Exists(outputFile))
Process.Start(outputFile);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// This is the main entry point for the application.
public static void Main(string[] args)
{
const string fontName = "Symbol";
const string printerName = "<Choose an installed Postscript printer here>";
const string textToPrint = "1234567890\r\nabcdefghijklmnopqrstuvwxyz";
var p = new PrintingExample(fontName, printerName, textToPrint);
p.Printing();
}
}
这原来是 Windows 2012R2、10、Server 2016 和 Server 2019 中的一个错误(服务器 2008R2 未受影响,这导致我们打开了一个 MS 案例)。只有一些字体受到影响。 Windows 10、Server 2016 和 Server 2019
的 2021 年 3 月 OS 更新解决了这个问题