![](/img/trans.png)
[英]Printing image with PrintDocument. how to adjust the image to fit paper size
[英]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.