【问题标题】:Symbol font is rasterized when printing from .NET application从 .NET 应用程序打印时,符号字体被光栅化
【发布时间】:2019-08-21 12:12:56
【问题描述】:

我通过打印到设置为打印到文件的 Postscript 打印机从 C# 创建 Postscript 文件。我正在使用 .NET PrintDocument 类和 Graphics.DrawString 来呈现文本。

如果我使用符号或象形文字字体(例如 Symbol 或 WingDings),则 Postscript 文件中的文本会被光栅化。如果我使用例如Arial,则文本未光栅化。我的目标是从我的应用程序中生成一个 Postscript 文件,其中使用符号字体的文本没有被光栅化。

如果我使用符号字体打印相同的文本,例如记事本中的文本没有被光栅化,因此乍一看似乎不是打印机驱动程序的限制。

我做错了什么/导致光栅化的不同之处?

  • 打印机的字体替换表设置为不替换字体。
  • Symbol 字体在我试用过的打印机上可用。
  • 选择另一个 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();
    }
}

【问题讨论】:

    标签: c# windows printing fonts


    【解决方案1】:

    这原来是 Windows 2012R2、10、Server 2016 和 Server 2019 中的一个错误(服务器 2008R2 不受影响,这导致我们打开了一个 MS 案例)。只有一些字体受到影响。它已在 2021 年 3 月的 Windows 10、Server 2016 和 Server 2019 操作系统更新中得到解决

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      相关资源
      最近更新 更多