web生成html文件,是一个10x10的标签。
我按照网上的代码将html转成图片,再用printdocumen打印,结果打印出来的标签很模糊。
如果直接调用webbrowser打印则很清晰,请教下是什么原因?(或者有没有其他的方式将html直接打印出来)
主要代码如下:
PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += new PrintPageEventHandler(this.pdoc_PrintPage);
PrintController pctl = new StandardPrintController();
pdoc.PrintController = pctl;
pdoc.Print();
private void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.HasMorePages = false;
string strHtml = "";
//strHtml = GetHTML(str);
strHtml = GetHtmlCSS();
GetImage thumb = new GetImage(strHtml, 393, 393, 393, 393);
System.Drawing.Bitmap bp = thumb.GetBitmap();
int width = bp.Width;
int height = bp.Height;
Rectangle destRect = new Rectangle(0, 0, width, height);
e.Graphics.DrawImage(bp, destRect, 0, 0, 100, 100, System.Drawing.GraphicsUnit.Millimeter);
}
Bitmap myBitmap = new Bitmap(Width, Height);
Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
MyBrowser.DrawToBitmap(myBitmap, DrawRect);
System.Drawing.Image imgOutput = myBitmap;
System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
Graphics g = Graphics.FromImage(oThumbNail);
Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
g.DrawImage(imgOutput, oRectangle);
return (Bitmap)oThumbNail;