2013-11-15 229 views
-1

我正在使用PrintDocuemnt类来打印记录。在运行时,我提供了字体大小,但是我在打印纸上得到小尺寸的字母。PrintDocument在打印纸上没有打印正确的字体大小

功能1:其与详细调用CreateCheckFormatForCheckWriter方法对象objTCWLDetailLayout和当前选择的对象

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); 
      } 
     } 

回答

1

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

+0

我更新了我使用Graphics.DrawString()的实际代码,参见我的更新代码 –

+0

你可以在设置'drawFont'的行上放置一个断点吗?哪种字体大小传递给构造函数?另外,'i'的价值是什么? – Stefan

+0

FontSize是6,Fontface是“Verdan”.objGlobalRulerbitmapData [i]它是包含data.i的int类型值的集合对象。 –