如何使用 C#.net 更改热敏打印 (lipi lwt 150) 中的字体大小

发布于 2024-07-17 02:01:25 字数 3074 浏览 7 评论 0原文

我正在使用 C#.net 和 GDI 打印代码打印到热敏打印机 LIPI LWT 150。但是,我无法更改字体大小。 我使用 Arial 9pt 和 5pt,但它以默认大小显示。 有人对此有任何想法吗?

我正在使用这样的 C# 代码:

 public frmSale()
        {
            InitializeComponent();
            printingDoc.PrintPage += new PrintPageEventHandler(Form_PrintPage);
        }

//initalizing print document
private void PrintSettings()
{

    printingDoc.DefaultPageSettings.Margins = new Margins(3, 3, 3, 3);
    PaperSize pSize = new PaperSize();
    pSize.Width = 275;
    printingDoc.DefaultPageSettings.PaperSize = pSize;

    // Claculating the PageWidth and the PageHeight
    PageHeight = printingDoc.DefaultPageSettings.PaperSize.Height;
    PageWidth = printingDoc.DefaultPageSettings.PaperSize.Width;
    // Claculating the page margins
    LeftMargin = printingDoc.DefaultPageSettings.Margins.Left;
    TopMargin = printingDoc.DefaultPageSettings.Margins.Top;
    RightMargin = printingDoc.DefaultPageSettings.Margins.Right;
    BottomMargin = printingDoc.DefaultPageSettings.Margins.Bottom;
    printAreaWidth = PageWidth - RightMargin - LeftMargin;

}

private void Form_PrintPage(object o, PrintPageEventArgs e)
//Here we Begin All the printing Process... 
{

       PrintSettings();
       CurrentY = (float)printingDoc.DefaultPageSettings.Margins.Top;//0;
       PrintEstHeader(e.Graphics);
        DrawEstGridData(e);

}

//Printing Function
private void PrintEstData(Graphics g, string stringData, StringAlignment alignment, Font fnt, Color clr, bool newLine)//,int starting,int maxWidth)
{
    StringFormat stringFormat = new StringFormat();
    stringFormat.Trimming = StringTrimming.Word;
    stringFormat.FormatFlags = StringFormatFlags.NoWrap |
        StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

    stringFormat.Alignment = alignment;

    RectangleF Rect = new RectangleF((float)LeftMargin, CurrentY,
                      (float)PageWidth - (float)RightMargin - (float)LeftMargin,
                      g.MeasureString(stringData, fnt).Height);

    g.DrawString(stringData, fnt,
       new SolidBrush(clr),
       Rect, stringFormat);

    CurrentY += newLine ? g.MeasureString(stringData, fnt).Height : 0;
 }

private void PrintEstHeader(Graphics g)
{

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//,LeftMargin,printAreaWidth);

    PrintEstData(g, "Estimate" + "    " + "Rate  :" + ncRate.Value.ToString("0.00"), StringAlignment.Near, new Font("Arial", 9, FontStyle.Bold), Color.Black, true);//, LeftMargin, 76);

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
    PrintEstData(g,"|ITEM |"+"WEIGHT|"+ "STN WT|"+"M.C. %|"+"Total|", StringAlignment.Near, new Font("Arial", 5), Color.Black, true);//,LeftMargin,42);
    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
}

I am using C#.net and GDI printing code to print to thermal printer LIPI LWT 150. But, I can't change my font size. I'm using Arial 9pt and 5pt, but it comes out in default size.
Does anybody have any idea about this?

I am using C# code like this:

 public frmSale()
        {
            InitializeComponent();
            printingDoc.PrintPage += new PrintPageEventHandler(Form_PrintPage);
        }

//initalizing print document
private void PrintSettings()
{

    printingDoc.DefaultPageSettings.Margins = new Margins(3, 3, 3, 3);
    PaperSize pSize = new PaperSize();
    pSize.Width = 275;
    printingDoc.DefaultPageSettings.PaperSize = pSize;

    // Claculating the PageWidth and the PageHeight
    PageHeight = printingDoc.DefaultPageSettings.PaperSize.Height;
    PageWidth = printingDoc.DefaultPageSettings.PaperSize.Width;
    // Claculating the page margins
    LeftMargin = printingDoc.DefaultPageSettings.Margins.Left;
    TopMargin = printingDoc.DefaultPageSettings.Margins.Top;
    RightMargin = printingDoc.DefaultPageSettings.Margins.Right;
    BottomMargin = printingDoc.DefaultPageSettings.Margins.Bottom;
    printAreaWidth = PageWidth - RightMargin - LeftMargin;

}

private void Form_PrintPage(object o, PrintPageEventArgs e)
//Here we Begin All the printing Process... 
{

       PrintSettings();
       CurrentY = (float)printingDoc.DefaultPageSettings.Margins.Top;//0;
       PrintEstHeader(e.Graphics);
        DrawEstGridData(e);

}

//Printing Function
private void PrintEstData(Graphics g, string stringData, StringAlignment alignment, Font fnt, Color clr, bool newLine)//,int starting,int maxWidth)
{
    StringFormat stringFormat = new StringFormat();
    stringFormat.Trimming = StringTrimming.Word;
    stringFormat.FormatFlags = StringFormatFlags.NoWrap |
        StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

    stringFormat.Alignment = alignment;

    RectangleF Rect = new RectangleF((float)LeftMargin, CurrentY,
                      (float)PageWidth - (float)RightMargin - (float)LeftMargin,
                      g.MeasureString(stringData, fnt).Height);

    g.DrawString(stringData, fnt,
       new SolidBrush(clr),
       Rect, stringFormat);

    CurrentY += newLine ? g.MeasureString(stringData, fnt).Height : 0;
 }

private void PrintEstHeader(Graphics g)
{

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//,LeftMargin,printAreaWidth);

    PrintEstData(g, "Estimate" + "    " + "Rate  :" + ncRate.Value.ToString("0.00"), StringAlignment.Near, new Font("Arial", 9, FontStyle.Bold), Color.Black, true);//, LeftMargin, 76);

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
    PrintEstData(g,"|ITEM |"+"WEIGHT|"+ "STN WT|"+"M.C. %|"+"Total|", StringAlignment.Near, new Font("Arial", 5), Color.Black, true);//,LeftMargin,42);
    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-07-24 02:01:26

根据打印机规范,它看起来不支持任意字体,但只支持两种内置固定宽度字体。 除非您可以将位图打印到打印机或创建用户字符,否则我怀疑您除了选择字体 A 或字体 B 之外是否还能做更多的事情。

Based on the printer specification it looks like it does not support arbitrary fonts, but only two inbuilt fixed width fonts. Unless you can print bitmaps to the printer or create user characters I doubt if you will be able to do more than select Font A or Font B.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文