我正在使用PrintDocuemnt类来打印记录。在运行时我提供的是字体大小,但我在打印纸上的字母很小。
功能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);
}
}
答案 0 :(得分:1)
您正在设置PaperSize,而不是实际的字体大小。您没有提供在PrintDocument
上绘制文本的代码,或者从未设置字体(类型/大小/等)。如果使用Graphics.DrawString绘制文本,则可以设置字体(及其大小)。