WEB水晶报表打印问题?????????????
tinki 2006-04-03 05:45:56 本人现在使用水晶报表9,想实现WEB下打印功能:
下面是函数,可是在寻找打印机上有问题:请问有没有好的解决方法:
private void btnPrint_Click(object sender, System.EventArgs e)
{
printerName=this.ddlPrint.SelectedItem.Text.ToString().Trim();//打印机名称
string sql="select * from OR_PR_O where PRNM='"+printerName+"'";//获取打印机路径
DataSet ds=conn.CreateDataSet(sql,"OR_PR_O");
string strPrinterName = @"\\"+ds.Tables[0].Rows[0]["PS"].ToString().Trim()+"\\"+printerName;//路径和名称
// if (printDoc.PrinterSettings.IsValid)
// {
// string sqlset="select * from XTCS_SET";
// ds=conn.CreateDataSet(sqlset,"XTCS_SET");
// if(ds.Tables[0].Rows[0]["ISCOLOR"].ToString().Trim()=="1")
// {
// printDoc.DefaultPageSettings.Color=true;
// }
// else
// {
// printDoc.DefaultPageSettings.Color=false;
// }
// (Server.MapPath("/DamSurvey")+"\\DataAdmin\\picture\\picture\\"+ImgFileName);
// filePath=Server.MapPath("../Report/Inter_TPPipe_TCTable.rpt");
// streamToPrint=new StreamReader(filePath);
// streamToPrint=new StreamReader("e:\\DamSurvey\\DataAdmin\\Report\\RPT\\Inter_TPPipe_TCTable.rpt");
// int leftMargins=System.Convert.ToInt32(ds.Tables[0].Rows[0]["RPTLEFT"].ToString().Trim());
// int topMargins=System.Convert.ToInt32(ds.Tables[0].Rows[0]["RPTTOP"].ToString().Trim());
// Margins margins = new Margins(100,100,100,100);
// printDoc.DefaultPageSettings.Margins=margins;
// printDoc.DefaultPageSettings.PaperSize=;
// string fontType=ds.Tables[0].Rows[0]["RPTFONT"].ToString().Trim();
string filePath=Server.MapPath("../Report/Inter_TPPipe_TCTable.rpt");
filePath=Server.MapPath("/DamSurvey")+"\\DataAdmin\\Report\\RPT\\Inter_TPPipe_TCTable.rpt";
printFont = new Font("Arial",10);
streamToPrint=new StreamReader(filePath);
printDoc.PrinterSettings.PrinterName="5D PDF Creator";
printDoc.PrintPage +=new PrintPageEventHandler(this.printDoc_PrintPage);
printDoc.DefaultPageSettings.Landscape=true;//横向打印
printDoc.Print();
// }
// else
// {
// Response.Write("<script>alert('打印机无效!');</script>");
// }
}
private void ddlPrint_SelectedIndexChanged(object sender, System.EventArgs e)
{
printerName=this.ddlPrint.SelectedItem.Text.ToString().Trim();//更改打印机名称
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="ev"></param>
private void printDoc_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height/printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
}