繁体   English   中英

PrintDocument无法在打印纸中打印正确的字体大小

[英]PrintDocument not printing correct font size in Printing Paper

我正在使用PrintDocuemnt类来打印记录。在运行时,我提供的是fontsize,但是在打印纸上的字母却变小了。

功能1:使用Details对象objTCWLDetailLayout和当前选定对象调用CreateCheckFormatForCheckWriter方法

List<Image> StringToPrint=new List<Image>;    
Image objInput = objCWLayout.CreateCheckFormatForCheckWriter(objTCWLDetailLayout,       objCWPrintCheck);                
 StringToPrint.Add(objInput);

函数2:哪个调用方法CreateCheckFormatForCheckWriter()

Image objCheckImage1 = null;
Graphics g = this.CreateGraphics(); // edited by jeet - assigned this.CreateGraphics()    
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = TextRenderingHint.AntiAlias;  
Brush P = new SolidBrush(Color.Black);
Pen pen = new Pen(Color.Black);
Draw_Check8_StringCompName(objGlobalRulerbitmapData, g, P, i, objCWPrintCheck.ChkCompanyName);

函数3:调用Draw_Check8_StringCompName()方法

 private void Draw_Check8_StringCompName(List<TCWLDetail> objGlobalRulerbitmapData, Graphics g, Brush P, int i, string strVal)
        {
            try
            {
                string fontFace = ("Vedana");
                int fontSize = 6;
                Font drawFont = new Font(fontFace, fontSize);
                float XCB = horizontalRuler.ScaleValueToPixel(objGlobalRulerbitmapData[i].FX);
                float YCB = verticalRuler.ScaleValueToPixel(objGlobalRulerbitmapData[i].FY);
               // float YCB = verticalRuler.ScaleValueToPixel((objGlobalRulerbitmapData[i].FY <=(float) 0.1 ?(float) 0.325 : objGlobalRulerbitmapData[i].FY));
                string sTemp = strVal;
                g.DrawString(sTemp, drawFont, P, XCB, YCB);
            }
            catch (Exception ex)
            {
                CusException cex = new CusException(ex);
                cex.Show(MessageBoxIcon.Error);
            }
        }

最后,我们在PrintDocument.StringToPrint上设置图像是List类型集合。

 private void PrintDocument_PrintPage(Object sender, PrintPageEventArgs e)
        {
            try
            {    //Set image from StringToPrint collection
                e.Graphics.DrawImage(StringToPrint[PageCounter], 6, 12, 816, 1256);                
                //PageCounter++;
                //e.HasMorePages = (PageCounter != StringToPrint.Count);

            }
            catch (Exception ex)
            {
                CusException cex = new CusException(ex);
                cex.Show(MessageBoxIcon.Error);
            }
        }

您正在设置PaperSize ,而不是实际的字体大小。 您可能没有提供在PrintDocument上绘制文本的代码,或者从未设置字体(类型/大小/等)。 如果使用Graphics.DrawString绘制文本,则可以设置字体(及其大小)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM